public ContentResult Save(int? id, FormCollection actionValues)
        {
            var action = new DataAction(actionValues);
            var changedEvent = DHXEventsHelper.Bind<Event>(actionValues);
            DHXSchedulerDataContext data = new DHXSchedulerDataContext();
            try
            {
                switch (action.Type)
                {
                    case DataActionTypes.Insert:
                        data.Events.InsertOnSubmit(changedEvent);
                        break;
                    case DataActionTypes.Delete:
                        changedEvent = data.Events.SingleOrDefault(ev => ev.id == action.SourceId);
                        data.Events.DeleteOnSubmit(changedEvent);
                        break;
                    default:// "update"
                        var eventToUpdate = data.Events.SingleOrDefault(ev => ev.id == action.SourceId);
                        DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
                        break;
                }
                data.SubmitChanges();
                action.TargetId = changedEvent.id;
            }
            catch (Exception a)
            {
                action.Type = DataActionTypes.Error;
            }

            return (new AjaxSaveResponse(action));
        }
        public ContentResult CustomFormSave(DataAction action, ValidEvent changedEvent, FormCollection actionValues)
        {
            if (actionValues["actionType"] != null)
            {
                var actionType = actionValues["actionType"].ToLower();
                var data = new DHXSchedulerDataContext();
                try
                {
                    if (actionType == "save")
                    {

                        if (data.ValidEvents.SingleOrDefault(ev => ev.id == action.SourceId) != null)
                        {
                            //update event
                            var eventToUpdate = data.ValidEvents.SingleOrDefault(ev => ev.id == action.SourceId);

                            DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });

                            action.Type = DataActionTypes.Update;
                        }
                        else
                        {
                            //create event
                            data.ValidEvents.InsertOnSubmit(changedEvent);
                            action.Type = DataActionTypes.Insert;
                        }
                    }
                    else if (actionType == "delete")
                    {

                        changedEvent = data.ValidEvents.SingleOrDefault(ev => ev.id == action.SourceId);
                        data.ValidEvents.DeleteOnSubmit(changedEvent);

                        action.Type = DataActionTypes.Delete;
                    }
                    data.SubmitChanges();
                }

                catch (Exception e)
                {
                    action.Type = DataActionTypes.Error;
                }
            }

            return (new SchedulerFormResponseScript(action, changedEvent));
        }
        public ActionResult CustomSave(Event changedEvent, FormCollection actionValues)
        {
            var action = new DataAction(DataActionTypes.Update, changedEvent.id, changedEvent.id);
            if (actionValues["actionButton"] != null)
            {
                DHXSchedulerDataContext data = new DHXSchedulerDataContext();
                try
                {
                    if (actionValues["actionButton"] == "Save")
                    {

                        if (data.Events.SingleOrDefault(ev => ev.id == action.SourceId) != null)
                        {
                            var eventToUpdate = data.Events.SingleOrDefault(ev => ev.id == action.SourceId);
                            DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
                        }
                        else
                        {
                            action.Type = DataActionTypes.Insert;
                            data.Events.InsertOnSubmit(changedEvent);
                        }
                    }else if(actionValues["actionButton"] == "Delete"){
                        action.Type = DataActionTypes.Delete;
                        changedEvent = data.Events.SingleOrDefault(ev => ev.id == action.SourceId);
                        data.Events.DeleteOnSubmit(changedEvent);
                    }
                    data.SubmitChanges();
                }

                catch (Exception e)
                {
                    action.Type = DataActionTypes.Error;
                }
            }
            else
            {
                action.Type = DataActionTypes.Error;
            }

            return (new SchedulerFormResponseScript(action, changedEvent));
        }
        public ActionResult Save(int? id, FormCollection actionValues)
        {
            var action = new DataAction(actionValues);

            DHXSchedulerDataContext data = new DHXSchedulerDataContext();
            try
            {
                var changedEvent = DHXEventsHelper.Bind<Recurring>(actionValues);
                //operations with recurring events require some additional handling
                bool isFinished = deleteRelated(action, changedEvent, data);
                if (!isFinished)
                {
                    switch (action.Type)
                    {

                        case DataActionTypes.Insert:
                            data.Recurrings.InsertOnSubmit(changedEvent);
                            if (changedEvent.rec_type == "none")//delete one event from the serie
                                action.Type = DataActionTypes.Delete;
                            break;
                        case DataActionTypes.Delete:
                            changedEvent = data.Recurrings.SingleOrDefault(ev => ev.id == action.SourceId);
                            data.Recurrings.DeleteOnSubmit(changedEvent);
                            break;
                        default:// "update"
                            var eventToUpdate = data.Recurrings.SingleOrDefault(ev => ev.id == action.SourceId);
                            DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
                            break;
                    }
                }
                data.SubmitChanges();

                action.TargetId = changedEvent.id;
            }
            catch (Exception a)
            {
                action.Type = DataActionTypes.Error;
            }

            return (new AjaxSaveResponse(action));
        }
        public ContentResult Save(int? id, FormCollection actionValues)
        {
            var action = new DataAction(actionValues);
            var changedEvent = DHXEventsHelper.Bind<Event>(actionValues);

            if (this.Request.IsAuthenticated && changedEvent.user_id == (Guid)Membership.GetUser().ProviderUserKey)
            {
                DHXSchedulerDataContext data = new DHXSchedulerDataContext();
                try
                {
                    switch (action.Type)
                    {
                        case DataActionTypes.Insert:
                            changedEvent.room_id = data.Rooms.First().key;
                            data.Events.InsertOnSubmit(changedEvent);
                            break;
                        case DataActionTypes.Delete:
                            changedEvent = data.Events.SingleOrDefault(ev => ev.id == action.SourceId);
                            data.Events.DeleteOnSubmit(changedEvent);
                            break;
                        default:// "update"
                            var eventToUpdate = data.Events.SingleOrDefault(ev => ev.id == action.SourceId);
                            DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
                            break;
                    }
                    data.SubmitChanges();
                    action.TargetId = changedEvent.id;
                }
                catch (Exception a)
                {
                    action.Type = DataActionTypes.Error;
                }
            }
            else
            {
                action.Type = DataActionTypes.Error;
            }
            return (new AjaxSaveResponse(action));
        }