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 Operation

Hi

Firstly, apologies for the quick message, I am about to duck off to work, and was hoping you might be able to provide a resolution before the weekend begins.

I am trying to write appointments back to the database, but am not having luck with the Batch method on the Controller.  It is just not being called (I put a breakpoint in, but it is never reached)

I have set my view up like this:

@model SyncfusionMvcApplicationCrud.Models.ScheduleModel
 
@{
    ViewBag.Title = "ScheduleFeatures";
}
<h2>ScheduleFeatures</h2>
 
<div>
 
    @(Html.EJ().Schedule("Schedule")
            .Width("100%")
            .Height("525px")
            .TimeZone("UTC +00:00")
            .TimeMode(Syncfusion.JavaScript.TimeMode.Hour24)
            .CurrentDate(DateTime.Now)
            .ShowCurrentTimeIndicator()
            .Views(new List<string>() { "Week" })
            .ShowQuickWindow(true)
            .AppointmentSettings(
                fields => fields.Datasource((IEnumerable<SyncfusionMvcApplicationCrud.Models.DefaultSchedule>)Model.Appointments)
                .Id("Id")
                .Subject("Subject")
                .Description("Description")
                .StartTime("StartTime")
                .EndTime("EndTime")
                .AllDay("AllDay")
                .Recurrence("Recurrence")
                .RecurrenceRule("RecurrenceRule"))
            .ScheduleClientSideEvents(=>
                 e.Create("onCreate")
            )
            .DateFormat("ddd dd/mm/yyyy")
    )
</div>
 
<script type="text/javascript">
 
    function onCreate(args) {
        debugger;
 
        this._dataManager.dataSource.crudUrl = "/Schedule/Batch";
    }
</script>
 
With the CRUD method signature in the controller: 

public JsonResult Batch(EditParams param)

The controller loads the data into my model, rather than using a GetData method on the controller.

Have I missed something?  Do you have an example to illustrate what I am trying to do please?

I have got a working example where the CRUD is working when the schedule is scripted:

$("#Schedule1").ejSchedule({
    width: "100%",
    height: "500px",

But I am hoping I can do it the first way.

Also, am I using the date format correctly?  It doesn't appear to change when I set the format as above. 

Thanks for your help.  I'm off to work now.

Cheers
Jarrod


3 Replies

VS Velmurugan S Syncfusion Team August 24, 2015 10:19 AM UTC

Hi Jarrod,
Thank you for using Syncfusion products.
Please find the following responses for your queries:
Query #1: CRUD operation sample

You can call the Batch action directly without using the client side event “create” and perform the CRUD operation. Please find the following code snippets to meet the requirement “CRUD operation in MVC application”.

<code>
ScheduleFeatures.cshtml:

                @(Html.EJ().Schedule("Schedule1")

        .Width("100%")

        .Height("525px")      

        .AppointmentSettings(fields => fields.Datasource(ds => ds.URL("/Schedule/GetData").CrudURL("/Schedule/Batch").Adaptor(AdaptorType.UrlAdaptor))

            .Id("Id")

            .Subject("Subject")

            .StartTime("StartTime")

            .EndTime("EndTime")

            .Description("Description")

            .AllDay("AllDay")

            .Recurrence("Recurrence")

            .RecurrenceRule("RecurrenceRule"))

       
)
</code>

Query #2: Date Format in Schedule

We have analyzed the reported scenario with the provided code snippets and found that the necessary dateformat was wrongly passed. Therefore, we suggest you to pass the date format properly to apply the given dateformat to the Syncfusion Controls. Please find the following code snippet to know about how to pass the date format to the Schedule control.
<code>

                @(Html.EJ().Schedule("Schedule1")

        .Width("100%")

        .Height("525px")

.DateFormat("ddd dd/MM/yyyy")    // Here we need to mention the dateformat string with proper cases to apply date format properly (ex: MM for month instead of mm))
</code>

We have prepared the sample with the above code snippets that can be downloaded from the following location. 
http://www.syncfusion.com/downloads/support/forum/120003/ze/SampleScheduleCRUD1148312314

Please let us know if you need further assistance on this.
Regards,
Velmurugan



JA jarrod August 25, 2015 09:31 AM UTC

Thanks very much, the CRUD is working perfectly now.

Now with the DateFormat, I think I may have the wrong end of the stick with it.  What exactly does this property control?  For some reason, I thought that it controlled the format of the date in the column header (I am operating in Week view mode), but now I am not sure I have that correct.   If it does, it is having no affect when I changed it.  If it doesn't control this, is there a way to change the format of the date at the column header?

Cheers
Jarrod



VS Velmurugan S Syncfusion Team August 26, 2015 01:43 PM UTC

Hi Jarrod,

Thanks for you update.
Please find the following responses for your queries:

Query #1: the CRUD is working perfectly now

We are glad to hear that the solution provided by us helped you to meet your requirement.

Query #2: is there a way to change the format of the date at the column header?

You can meet the above mentioned requirement in our Schedule control using our client side events. Please refer the following code snippets that will help you to meet the requirement.

<code>

                @(Html.EJ().Schedule("Schedule1")

        .Width("100%")

        .Height("525px")

        .TimeZone("UTC +00:00")

        .TimeMode(Syncfusion.JavaScript.TimeMode.Hour24)

        .CurrentDate(DateTime.Now)

        .ShowCurrentTimeIndicator()

        .Views(new List<string>() { "Week" })

        .ShowQuickWindow(true)

        .AppointmentSettings(fields => fields.Datasource(ds => ds.URL("/Schedule/GetData").CrudURL("/Schedule/Batch").Adaptor(AdaptorType.UrlAdaptor))

            .Id("Id")

            .Subject("Subject")

            .StartTime("StartTime")

            .EndTime("EndTime")

            .Description("Description")

            .AllDay("AllDay")

            .Recurrence("Recurrence")

            .RecurrenceRule("RecurrenceRule"))

        .DateFormat("ddd dd/MM/yyyy")    // Here we need to mention the with proper cases to apply date format properly (ex: MM for month instead of mm)

        .ScheduleClientSideEvents(evt =>evt.Create("onCreate").ActionComplete("onCreate"))



)


<script>

    function onCreate() {  // The following code snippet is used to display the column header date in specified format

        var obj = $("#Schedule1").data("ejSchedule");

        if (obj.currentView() != "month") {

            for (var i = 0; i < obj.dateRender.length; i++) {

                var temp = Globalize.format(new Date(obj.dateRender[i]), obj.model.dateFormat);

                obj.element.find(".e-headerdaydisplay")[i].innerHTML = temp;

            }

        }

    }
</script>

</code>
We have modified the sample with the above code snippets, which can be downloaded from the following location.
http://www.syncfusion.com/downloads/support/forum/120003/ze/SampleScheduleCRUD1562197851

Please let us know if it helps and if you need any further assistance on this.
Regards,
Velmurugan


Loader.
Live Chat Icon For mobile
Up arrow icon