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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CRUD operations not working

Thread ID:

Created:

Updated:

Platform:

Replies:

143650 Mar 29,2019 08:02 PM UTC Apr 10,2019 05:05 AM UTC ASP.NET Core - EJ 2 17
loading
Tags: Scheduler
Gregory Perozzo
Asked On March 29, 2019 08:17 PM UTC

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?

Vinitha Devi Murugan [Syncfusion]
Replied On 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. 


Gregory Perozzo
Replied On 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.):



Gregory Perozzo
Replied On 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.

Gregory Perozzo
Replied On April 3, 2019 12:53 PM UTC

Hello!

Any updates on this issue?

Nevitha Ravi [Syncfusion]
Replied On 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. 
 


Gregory Perozzo
Replied On 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!




Gregory Perozzo
Replied On 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.


Gregory Perozzo
Replied On 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:






Gregory Perozzo
Replied On 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!

Nevitha Ravi [Syncfusion]
Replied On 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 


Gregory Perozzo
Replied On 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!

Vinitha Devi Murugan [Syncfusion]
Replied On 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. 


Gregory Perozzo
Replied On 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!

Karthigeyan Krishnamurthi [Syncfusion]
Replied On 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 


Gregory Perozzo
Replied On 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!

Gregory Perozzo
Replied On 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?



Karthigeyan Krishnamurthi [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;