public ContentResult Save(int?id, FormCollection actionValues)
        {
            var action = new DataAction(actionValues);

            var changedEvent             = DHXEventsHelper.Bind <ColoredEvent>(actionValues);
            CustomFieldsDataContext data = new CustomFieldsDataContext();

            try
            {
                switch (action.Type)
                {
                case DataActionTypes.Insert:
                    data.ColoredEvents.InsertOnSubmit(changedEvent);
                    break;

                case DataActionTypes.Delete:
                    changedEvent = data.ColoredEvents.SingleOrDefault(ev => ev.id == action.SourceId);
                    data.ColoredEvents.DeleteOnSubmit(changedEvent);
                    break;

                default:    // "update"
                    var eventToUpdate = data.ColoredEvents.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));
        }
示例#2
0
        public ContentResult Save(int?id, FormCollection actionValues)
        {
            var action       = new DataAction(actionValues);
            var changedEvent = (ColoredEvent)DHXEventsHelper.Bind(typeof(ColoredEvent), actionValues);
            var color        = "";

            if (actionValues["color"] == "#FE7510")
            {
                color = "#FE7510";
            }
            else
            {
                if (changedEvent.start_date < DateTime.Now)
                {
                    color = "#ccc";
                }
                else
                {
                    color = "#76B007";
                }
            }

            CustomFieldsDataContext data = new CustomFieldsDataContext();

            try
            {
                switch (action.Type)
                {
                case DataActionTypes.Insert:
                    changedEvent.color = color;
                    data.ColoredEvents.InsertOnSubmit(changedEvent);
                    break;

                case DataActionTypes.Delete:
                    changedEvent = data.ColoredEvents.SingleOrDefault(ev => ev.id == action.SourceId);
                    data.ColoredEvents.DeleteOnSubmit(changedEvent);
                    break;

                default:    // "update"
                    var eventToUpdate = data.ColoredEvents.SingleOrDefault(ev => ev.id == action.SourceId);
                    DHXEventsHelper.Update(eventToUpdate, changedEvent, new List <string>()
                    {
                        "id"
                    });

                    changedEvent.color = color;


                    break;
                }
                data.SubmitChanges();
                action.TargetId = changedEvent.id;
            }
            catch
            {
                action.Type = DataActionTypes.Error;
            }

            var result = new AjaxSaveResponse(action);

            result.UpdateField("color", color);//property will be updated on the client
            return(result);
        }