Пример #1
0
 public ContentResult Save(int? id, FormCollection actionValues)
 {
     var action = new DataAction(actionValues);
     CustomFieldsDataContext data = new CustomFieldsDataContext();
     try
     {
         var changedEvent = (Grid)DHXEventsHelper.Bind(typeof(Grid), actionValues);
         switch (action.Type)
         {
             case DataActionTypes.Insert:
                 data.Grids.InsertOnSubmit(changedEvent);
                 break;
             case DataActionTypes.Delete:
                 changedEvent = data.Grids.SingleOrDefault(ev => ev.id == action.SourceId);
                 data.Grids.DeleteOnSubmit(changedEvent);
                 break;
             default:// "update"
                 var eventToUpdate = data.Grids.SingleOrDefault(ev => ev.id == action.SourceId);
                 DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
                 break;
         }
         data.SubmitChanges();
         action.TargetId = changedEvent.id;
     }
     catch
     {
         action.Type = DataActionTypes.Error;
     }
     return (new AjaxSaveResponse(action));
 }
        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;
        }