We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

CRUD operations not working

Hello, 

I'm following this tutorial to add CRUD operations to the scheduler: https://ej2.syncfusion.com/aspnetcore/documentation/schedule/data-binding/#performing-crud-actions

The problem is that this tutorial is a little bit outdated and some things changes in .NET Core.

1. For example, JsonRequestBehavior has been deprecated in ASP.NET Core 1.0.

2. In UpdateData method inside the Controller, the class EditParams doesn't exist. 

3. Another thing is that when I execute the method 'GetData' to get appointment data, the method is executed twice (checked it with a break-point inside Visual Studio) and after the return, nothing is added to the scheduler.

No error is shown in the browser console.

This is the DataManager setup:

@using Syncfusion.EJ2
@{
    var ValidationRules = new Dictionary() { { "required", true } };
    var DateValidation = new Dictionary() { { "required", true } };
    var dataManager = new DataManager() { Url = "GetData", Adaptor = "UrlAdaptor", CrudUrl = "UpdateData", CrossDomain = true };
}

This is my GetData method:

        public async Task GetData()
        {
            var schedule = await GetScheduleData(DateTime.Now.ToString("dd/MM/yyyy"), null, User.Identity.Name);

            return Json(schedule);
        }

There is an updated tutorial for CRUD operations in .NET Core? 

Can you help me?

21 Replies

VD Vinitha Devi Murugan Syncfusion Team April 1, 2019 01:20 PM UTC

Hi Gregory, 
 
Thank you for contacting Syncfusion Support. 
 
1.We have prepared the sample in core 2.1 with Json- formatted data, which can be downloaded from the following link.  
 
2.We have already logged task for revamping the EJ2 Core UG, and we will include the reported scenarios also with that. And this will be refreshed online on 10th April, 2019. 
 
3. By default post will hit twice. 
  1. A pre-flight request with the OPTIONS method is sends, so that the can respond whether it is acceptable to send the request with this parameters.  
  2. Then the actual request is sent that will be a POST request method, which will retrieve the scheduler data.
Kindly check whether any data available in schedule variable and share your GetScheduleData method to proceed further. 
 
  public async Task GetData() 
        { 
            var schedule = await GetScheduleData(DateTime.Now.ToString("dd/MM/yyyy"), null, User.Identity.Name); 
 
            return Json(schedule); 
        } 
 
 
Regards, 
M.Vinitha devi. 



GP Gregory Perozzo April 1, 2019 02:34 PM UTC

Hello Vinitha!

I have downloaded your sample and I'm following it.

I'm still having problems to show the data on the scheduler.

The 'schedule' variable has data on it. I double check it.

This is my method to get the data:

        [HttpPost]
        public async Task LoadData()
        {
            var schedule = await GetScheduleData(DateTime.Now.ToString("dd/MM/yyyy"), null, User.Identity.Name);

            return Json(schedule);
        }

The GetScheduleData method returns a list of ScheduleEvent: 

        Task> GetScheduleData(string date, Schedule schedule, string username)

The ScheduleEvent is:

    public class ScheduleEvent
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public string Date { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public string StartTimezone { get; set; }
        public string EndTimezone { get; set; }
        public bool IsAllDay { get; set; }
        public string Status { get; set; }
        public string Plate { get; set; }
        public string Workload { get; set; }
        public string ListStudent { get; set; }
        public string ListTeacher { get; set; }
        public string ListVehicle { get; set; }
        public string ListWorkload { get; set; }
        public string Color { get; set; }
        public bool IsReadonly { get; set; }
    }

And this is the ejs schedule setup (Not able to put the code here. I think the editor think is a html code to render. So I uploaded an image.):




GP Gregory Perozzo April 1, 2019 02:54 PM UTC

Hello Vinitha,

In your sample, inside DbInitializer class some data is loaded to the appointments. I changed the date to 2019, but nothing is shown either on the scheduler.

        public static void Initialize(ScheduleDataContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.ScheduleEvents.Any())
            {
                return;   // DB has been seeded
            }

            var appointments = new ScheduleEvent[]
            {
            new ScheduleEvent{Id=1, Subject="Meeting", StartTime= new DateTime(2019,3,27,10,00,00), EndTime=new DateTime(2019,3,27,11,00,00),  IsAllDay=false},
            new ScheduleEvent{Id=2, Subject="Client Demo", StartTime= new DateTime(2019,3,28,10,00,00), EndTime=new DateTime(2019,3,28,11,00,00),  IsAllDay=false},

            };
            foreach (ScheduleEvent app in appointments)
            {
                context.ScheduleEvents.Add(app);
            }
            context.SaveChanges();
        }
    }

I think this is related to a problem in the scheduler itself to render the data.


GP Gregory Perozzo April 3, 2019 12:53 PM UTC

Hello!

Any updates on this issue?


NR Nevitha Ravi Syncfusion Team April 3, 2019 04:38 PM UTC

Hi Gregory, 
  
Thanks for your update. 
  
We have analysed the provided code details and we suspect that the issue might be due to any of your customization within the application which hidden the appointment. Can you please provide us the following details so that we could able replicate the issue and provide you a solution at earlier. 
  
  • Share the response screenshot of LoadData method in network tab.
  • Can you please share us the customization codes done in sample.
  
We have attached the sample in which we have tested the issue. Please check this sample and if the issue persists on your side please modify the sample based o your scenario and revert us . 
  
Regards, 
M.Vinitha devi. 
 



GP Gregory Perozzo April 3, 2019 05:09 PM UTC

Hello Nevitha!

1. Share the response screenshot of LoadData method in network tab.



  •  Json

[{"id":110228,"subject":"ALUNO GREGORY 3 (871.235.520-83)","date":"quarta-feira, 3 de abril de 2019","startTime":"2019-04-03T10:39:00","endTime":"2019-04-03T11:29:00","startTimezone":null,"endTimezone":null,"isAllDay":false,"status":"Agendada","plate":"BLE-0001","workload":"50 minutos","listStudent":"ALUNO GREGORY 3 (871.235.520-83)","listTeacher":"INSTRUTOR RENAN (727.945.716-99)","listVehicle":"BLE-0001","listWorkload":"50 minutos","color":"#4d79ff","isReadonly":false}]


2. Can you please share us the customization codes done in sample.

Sorry, I don't understand. What customization?

____________________________

I will check your new sample and try to execute it here.

Thank you very much!





GP Gregory Perozzo April 3, 2019 05:24 PM UTC

Hello!

When running your example, I have the following error on Main method:

Cannot insert explicit value for identity column in table 'ScheduleEvent' when IDENTITY_INSERT is set to OFF.



So, I changed the GetData() method to this:



And the scheduler loaded perfectly.

So now, I'll do my customization in your sample and check if it works.

Thanks for now.



GP Gregory Perozzo April 3, 2019 06:52 PM UTC

Hello!

I think I discovered the problem.

The data was not showing in the scheduler due to the date format I'm using.

I changed your sample to get the data as my project does.

This is what I am using:

                DateTime start = Convert.ToDateTime($"{item.SchedulingDate} {item.SchedulingHour}") = {3/4/2019 10:00:00 AM};
                DateTime end = item.WorkloadID == 1 ? start.AddMinutes(50) : start.AddMinutes(100) = {3/4/2019 11:00:00 AM};

And this is what your sample uses:

                 StartTime = new DateTime(2019, 4, 3, 10, 00, 00) = {4/3/2019 10:00:00 AM};
                 EndTime = new DateTime(2019, 4, 3, 11, 00, 00) = {4/3/2019 11:00:00 AM} ;

This change, only worked in your sample. In my sample, still not working.

But in my project, I changed the date format:







GP Gregory Perozzo April 3, 2019 07:21 PM UTC

Hello, 

I think finally resolved the problem.

I changed the date conversion from:

Convert.ToDateTime

To:

DateTime.ParseExact($"{item.SchedulingDate} {item.SchedulingHour}", "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);

And the data appears normally on the scheduler.

I'll keep running some tests here and let you know about it.

Thank you very much!


NR Nevitha Ravi Syncfusion Team April 4, 2019 05:51 AM UTC

Hi Gregory, 

Thanks for your update. 

We are happy that your issue ‘appointments not shown’ resolved at your end, please let us know if you need further assistance. 

Regards, 
Nevitha 



GP Gregory Perozzo April 4, 2019 04:39 PM UTC

Hello Nevitha!

I notice that in your sample the GetData() method is executed only once and in my project it executes twice.

Can you explain me why?

Thank you very much!


VD Vinitha Devi Murugan Syncfusion Team April 5, 2019 01:46 PM UTC

Hi Gregory, 
 
In our previously shared project we are not enabling the CORS in startup page. So that request doesn’t trigger the preflight(OPTION) those are called simple request. 
Kindly refer below link to know more about simple request. 

 
For enabling the CORS kindly go through the below link. 
 
 
Regards, 
M.Vinitha devi. 



GP Gregory Perozzo April 8, 2019 06:20 PM UTC

Hello Vinitha!

Thank you for your response about the CORS problem!

So, back to the original problem, I made work the GetData method and it's perfectly working.

Now I'm having problem with the CrudData method. 

In my project and in your project, the EditParams parameter is coming with almost all properties null.



Any ideas why this is happening?

Thank you!


KK Karthigeyan Krishnamurthi Syncfusion Team April 9, 2019 06:29 AM UTC

Hi Gregory,  
 
Thanks for your update. 
 
Please try using [FromBody] like below.  
 
public JsonResult CrudData ([FromBody]EditParams param) 
 
public class EditParams 
    { 
        public string key { get; set; } 
        public string action { get; set; } 
        public List<ScheduleEvent> added { get; set; } 
        public List<ScheduleEvent> changed { get; set; } 
        public List<ScheduleEvent> deleted { get; set; } 
        public ScheduleEvent value { get; set; } 
    } 
 
Regards, 
Karthi 



GP Gregory Perozzo April 9, 2019 11:36 AM UTC

Hello Karthigeyan!

It worked perfectly.

Thank you very much for your time and answer.

Have a nice day!


GP Gregory Perozzo April 9, 2019 05:03 PM UTC

Hello once again,

I have another doubt.

How can I send an error message to the user in case something wrong happens inside the CrudData method?




KK Karthigeyan Krishnamurthi Syncfusion Team April 10, 2019 05:05 AM UTC

Hi Gregory, 
 
We are happy that our solution fulfilled your requirement. 
 
Kindly try ActionFailure event and refer the below link. 
 
Regards, 
Karthi 



GU Guillermo replied to Karthigeyan Krishnamurthi March 5, 2020 09:12 AM UTC

Hi Gregory,  
 
Thanks for your update. 
 
Please try using [FromBody] like below.  
 
public JsonResult CrudData ([FromBody]EditParams param) 
 
public class EditParams 
    { 
        public string key { get; set; } 
        public string action { get; set; } 
        public List<ScheduleEvent> added { get; set; } 
        public List<ScheduleEvent> changed { get; set; } 
        public List<ScheduleEvent> deleted { get; set; } 
        public ScheduleEvent value { get; set; } 
    } 
 
Regards, 
Karthi 


Hello.
I have the same problem with de EditParam==null. (WITH NETCORE 3.1)
EJ2 and vs2019 are updated at the last version.
The solution inhttp://www.syncfusion.com/downloads/support/forum/143650/ze/ScheduleCrud1791272701 works with netcore 2.1, but not for me in netcore3.1

I think the problem is related to microsoft's changes with json in netcore31, which affect the EJ2 scheduler component.
I attach information about it........
Thanks a lot



BS Balasubramanian Sattanathan Syncfusion Team March 6, 2020 10:21 AM UTC

Hi Guillermo, 
 
Thanks for the update. 
 
We have analyzed your reported problem at our end. We suspect that you are facing the problem due to the deprecated package “AddJsonOptions. So we suggest you to use below code snippets to overcome the reported issue. Please refer the below link for more about NewtonsoftJson 
 
 
using Microsoft.AspNetCore.Mvc.NewtonsoftJson; 

public void ConfigureServices(IServiceCollection services)
 
{ 
      services.AddDbContext<ScheduleDataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ScheduleDataConnection"))); 
      services.AddMvc(option => option.EnableEndpointRouting = false).AddNewtonsoftJson(); 
     services.AddMvc() 
                .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()) 
                .AddNewtonsoftJson(opt => opt.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat) 
                .AddNewtonsoftJson(opt => opt.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local); 
} 
 
 
Kindly try the above sample and let us know if you have any concerns. 
 
Regards, 
Balasubramanian S


GU Guillermo March 9, 2020 07:30 AM UTC

Hello again. Your explanation solves the problem and it works.
Thank you very much for the time and for the example in netcore 3.0.


VM Vengatesh Maniraj Syncfusion Team March 10, 2020 04:34 AM UTC

Hi Guillermo, 
 
Thanks for the update. 
 
We are happy that your problem has resolved. 
 
Regards, 
Vengatesh 


Loader.
Live Chat Icon For mobile
Up arrow icon