/// <summary> /// The save. /// </summary> /// <param name="id"> /// The id. /// </param> /// <param name="actionValues"> /// The action values. /// </param> /// <param name="officeId"> /// The office Id. /// </param> /// <param name="userId"> /// The user Id. /// </param> /// <returns> /// The <see cref="ContentResult"/>. /// </returns> public ContentResult Save(int?id, FormCollection actionValues, int officeId, int userId) { var employeeId = this.appointmentManager.GetEmployeeIdByUserId(userId).GetValueOrDefault(); var action = new DataAction(actionValues); var changedEvent = DHXEventsHelper.Bind <DhxAppointment>(actionValues); changedEvent.ErrorMessages = string.Empty; try { switch (action.Type) { case DataActionTypes.Insert: case DataActionTypes.Update: changedEvent = this.appointmentManager.SaveAppointment( changedEvent, employeeId, officeId, false, false); break; case DataActionTypes.Delete: this.appointmentManager.DeleteAppointment(changedEvent.id, employeeId); break; default: action.Type = DataActionTypes.Error; break; } action.TargetId = changedEvent.id; } catch { action.Type = DataActionTypes.Error; } if (!string.IsNullOrEmpty(changedEvent.ErrorMessages)) { action.Type = DataActionTypes.Error; action.Message = changedEvent.ErrorMessages; } else { action.Message = changedEvent.text; } var response = new AjaxSaveResponse(action); response.UpdateField("start_date", changedEvent.start_date); response.UpdateField("end_date", changedEvent.end_date); return(this.Content(response, "text/xml")); }
public ActionResult Save(Task task) { // an action against particular task (updated/deleted/created) var action = new DataAction(Request.Form); #region check rights if (!RoleIs("Manager")) { action.Type = DataActionTypes.Error; return(new AjaxSaveResponse(action)); } #endregion task.creator_id = Guid.Parse(AppUserManagerProvider.UserId); try { switch (action.Type) { case DataActionTypes.Insert: Repository.Insert(task); break; case DataActionTypes.Delete: Repository.Delete(task); break; case DataActionTypes.Update: Repository.Update(task); break; } action.TargetId = task.id; } catch (Exception) { action.Type = DataActionTypes.Error; } var color = Repository.GetAll <Status>().SingleOrDefault(s => s.id == task.status_id); var result = new AjaxSaveResponse(action); result.UpdateField("color", color.color); return(result); }
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); }
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; }