public ContentResult Save(int? id, FormCollection actionValues) { var action = new DataAction(actionValues); var changedEvent = DHXEventsHelper.Bind<ColoredEvent>(actionValues); var color = ""; if (actionValues["textColor"] == "red") { color = "red"; } else { if (changedEvent.start_date < DateTime.Now) color = "gray"; else color = "blue"; } CustomFieldsDataContext data = new CustomFieldsDataContext(); try { switch (action.Type) { case DataActionTypes.Insert: changedEvent.textColor = 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.textColor = color; break; } data.SubmitChanges(); action.TargetId = changedEvent.id; } catch (Exception a) { action.Type = DataActionTypes.Error; } var result = new AjaxSaveResponse(action); result.UpdateField("textColor", color);//property will be updated on the client return result; }
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)); }