Gantt Chart WebApi Post or Put Action
Hi,
I want to use WebApiAdaptor for gantt chart with this code.
<SfGantt TValue="ProjectDto" Height="450px" Width="1200px" WorkUnit="WorkUnit.Hour">
<SfDataManager Url="api/Project" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true"></SfDataManager>
<GanttTaskFields Id="ProjectId" Name="TaskName" StartDate="StartDate" EndDate="EndDate"
Duration="Duration" Progress="Progress" ParentID="ParentId" ResourceInfo="Resources">
</GanttTaskFields>
<GanttEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" AllowTaskbarEditing="true"></GanttEditSettings>
<GanttResourceFields Resources="@ResourceCollection" Id="ResourceId" Name="ResourceName" Unit="Unit" Group="Group"
TResources="ProjectResourceDto"></GanttResourceFields>
<GanttLabelSettings RightLabel="Resources" TValue="ProjectDto"></GanttLabelSettings>
<GanttEvents TValue="ProjectDto" OnActionFailure="ActionFailure" ></GanttEvents>
</SfGantt>
So I wrote the controller and get the data from Get method, but I want to try POST or PUT method , i recieved Bad Request response status code.
My post method like this;
public void Post([FromBody] List<ProjectDto> projects)
and also Put like this
public void Put([FromBody] ProjectDto project)
How can i fix this error ?
Hi Gvardal,
Greetings from Syncfusion,
We have reviewed the Gantt Chart query, but we are unable to replicate the
issue. We are using the webApiController's get method to return the value as a
list, and the Gantt Chart is rendering properly. We have attached a code
snippet and sample for reference.
Video reference: https://www.syncfusion.com/downloads/support/directtrac/general/ze/wepApi2100706713
|
// index.razor Toolbar="@(new List<string>(){ "Add", "Edit", "Update", "Cancel", "Delete", "Indent","Outdent", "ExpandAll", "CollapseAll", "PrevTimeSpan", "NextTimeSpan"})"> <SfDataManager Url="/api/WebApi" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager> <GanttTaskFields Id="ID" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Duration="Duration" Dependency="Predecessor" ParentID="ParentId" Progress="Progress"> </GanttTaskFields> <GanttEditSettings AllowTaskbarEditing="true" AllowEditing="true" AllowAdding="true" AllowDeleting="true"> </GanttEditSettings> </SfGantt> |
|
//program.cs using Microsoft.AspNetCore.Components.Web; using Syncfusion.Blazor; using WepApiAdap.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddSyncfusionBlazor(); builder.Services.AddSingleton<WeatherForecastService>();
var app = builder.Build();
// Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); }
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); app.MapDefaultControllerRoute(); app.Run();
|
|
// WebApiController.cs [ApiController] public class WebApiController : ControllerBase { // GET: api/<WebApiController> [HttpGet] public object Get() { if (TaskData.ganttData.Count == 0) { TaskData.GetTree(); } IEnumerable dataList = TaskData.ganttData.ToList(); int count = dataList.Cast<TaskData>().Count(); return new { Items = dataList, Count = count }; }
// POST api/<WebApiController> [HttpPost] public void Post(List<TaskData> records) { for (var i = 0; i < records.Count(); i++) { TaskData.ganttData.Insert(0, records[i]); } }
// PUT api/<WebApiController>/5 [HttpPut] public void Put(TaskData item) { var result = TaskData.ganttData.Where(or => or.ID == item.ID).FirstOrDefault(); result.ID = item.ID; result.TaskName = item.TaskName; result.StartDate = item.StartDate; result.EndDate = item.EndDate; result.Duration = item.Duration; result.Progress = item.Progress; result.Predecessor = item.Predecessor; result.ParentId = item.ParentId; result.Assignee = item.Assignee; result.StoryPoint = item.StoryPoint; }
// DELETE api/<WebApiController>/5 [HttpDelete("{List<TaskData>}")] public void Delete(List<TaskData> items) { foreach (var rec in items) { TaskData.ganttData.Remove(TaskData.ganttData.Where(or => or.ID == rec.ID).FirstOrDefault()); } } } |
Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WepApiAdap540415554
However, we understand that you are still facing the issue. To assist us in
further investigating and addressing the problem, we kindly request the
following:
- Complete Gantt code example.
- Specific scenario you have faced the issue(Video demo)
- If you have made any modifications at the sample level, please share the details.
- If possible, please replicate the issue in the shared sample and revert back to us.
- If possible, could you provide us with a sample that replicates the issue you are experiencing? This would greatly aid us in identifying the problem and finding a solution.
Once we receive this information, we
will be better equipped to identify the root cause of the issue and provide you
with the necessary assistance.
Regards,
Ajithkumar G
- 1 Reply
- 2 Participants
-
GV gvardal
- Sep 14, 2023 07:00 AM UTC
- Sep 15, 2023 01:17 PM UTC