Pages

Monday, August 26, 2013

Calendar Scheduler In MVC4

Calendar Scheduler:using DHXScheduler dll

Code In Controller:
 public class CalendarController : Controller
    {
      Entities1 entity = new Entities1();
        public ActionResult Index()
        {
            //Being initialized in that way, scheduler will use CalendarController.Data as a the datasource and CalendarController.Save to process changes
            var scheduler = new DHXScheduler(this);

            /*
             * It's possible to use different actions of the current controller
             *      var scheduler = new DHXScheduler(this);  
             *      scheduler.DataAction = "ActionName1";
             *      scheduler.SaveAction = "ActionName2";
             *
             * Or to specify full paths
             *      var scheduler = new DHXScheduler();
             *      scheduler.DataAction = Url.Action("Data", "Calendar");
             *      scheduler.SaveAction = Url.Action("Save", "Calendar");
             */

            /*
             * The default codebase folder is ~/Scripts/dhtmlxScheduler. It can be overriden:
             *      scheduler.Codebase = Url.Content("~/customCodebaseFolder");
             */
         

            scheduler.InitialDate = new DateTime(2012, 09, 03);

            scheduler.LoadData = true;
            scheduler.EnableDataprocessor = true;

            return View(scheduler);
        }
     

        public ContentResult Data()
        {

            var data = new SchedulerAjaxData(new eCRM_MastersEntities1().Events);
                                     
            return (ContentResult)data;
        }

        public ContentResult Save(eCRM_Entity.Event updateevents, FormCollection actionValues)
        {
            var action = new DataAction(actionValues);
            entity = new eCRM_MastersEntities1();

            try
            {
                //var changedEvent = (Tbl_Calendar)DHXEventsHelper.Bind(typeof(Tbl_Calendar), actionValues);



                switch (action.Type)
                {
                    case DataActionTypes.Insert:
                        //do insert
                        entity.Events.Add(updateevents);

                        break;
                    case DataActionTypes.Delete:
                        //do delete
                        break;
                    default:// "update"                        
                        //do update
                        break;
                }
                entity.SaveChanges();
                action.TargetId = updateevents.id;
            }
            catch
            {
                action.Type = DataActionTypes.Error;
            }
            return (ContentResult)new AjaxSaveResponse(action);
        }
    }

In Model:
using System;
    using System.Collections.Generic;

    public partial class Event
    {
        public int id { get; set; }
        public string text { get; set; }
        public System.DateTime start_date { get; set; }
        public System.DateTime end_date { get; set; }
        public Nullable<int> UserId { get; set; }
    }

In View
@{
    Layout = "~/Views/Shared/_UserLayout.cshtml";
    ViewBag.Title = "Event Calender";
}




 <h2 class="topHeader">
    Events Details:</h2>
    <br />
    <div style="height:700px;width:900px;">
        @Html.Raw(Model.Render())
    </div>

Add  DHXScheduler  Dll :



Example :


No comments:

Post a Comment