/// <summary> /// Update event data /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel UpdateEventData(XEditableModel model) { var item = GetById(model.Pk); if (item != null) { var property = ReflectionUtilities.GetAllPropertiesOfType(typeof(EventManageModel)) .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase)); if (property != null) { object value = model.Value.ToType(property, WorkContext.CurrentTimezone); #region Validate var manageModel = new EventManageModel(item); manageModel.SetProperty(model.Name, value); var validationResults = manageModel.ValidateModel(); if (validationResults.Any()) { return(new ResponseModel { Success = false, Message = validationResults.BuildValidationMessages() }); } #endregion item.SetProperty(model.Name, value); var response = Update(item); return(response.SetMessage(response.Success ? T("Event_Message_UpdateEventInfoSuccessfully") : T("Event_Message_UpdateEventInfoFailure"))); } return(new ResponseModel { Success = false, Message = T("Event_Message_PropertyNotFound") }); } return(new ResponseModel { Success = false, Message = T("Event_Message_ObjectNotFound") }); }
public ActionResult PopupEdit(EventManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _eventService.SaveEvent(model); SetResponseMessage(response); if (response.Success) { switch (submit) { case SubmitType.PopupSave: return(View("CloseFancyBox", new CloseFancyBoxViewModel { IsReload = true })); case SubmitType.SaveAndContinueEdit: return(RedirectToAction("PopupEdit", new { id = model.Id })); } } } return(View(model)); }
public ActionResult Edit(EventManageModel model, string returnUrl, SubmitType submit) { if (ModelState.IsValid) { var response = _eventService.SaveEvent(model); SetResponseMessage(response); if (response.Success) { switch (submit) { case SubmitType.Save: if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } return(RedirectToAction("Index")); default: return(RedirectToAction("Edit", new { id = model.Id, returnUrl })); } } } return(View(model)); }
/// <summary> /// Save event /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveEvent(EventManageModel model) { ResponseModel response; var item = GetById(model.Id); if (item != null) { item.Title = model.Title; item.EventSummary = model.EventSummary; item.EventDescription = model.EventDescription; item.MaxAttendees = model.MaxAttendees; item.RegistrationFullText = model.RegistrationFullText; item.RegistrationWaiver = model.RegistrationWaiver; response = Update(item); if (model.EventCategoryIds == null) { model.EventCategoryIds = new List <int>(); } var currentCategorys = item.EventEventCategories != null ? item.EventEventCategories.Select(t => t.EventCategoryId).ToList() : new List <int>(); var removedCategoryIds = currentCategorys.Where(id => !model.EventCategoryIds.Contains(id)); _eventEventCategoryRepository.Delete(item.Id, removedCategoryIds); var addedCategoryIds = model.EventCategoryIds.Where(id => !currentCategorys.Contains(id)); _eventEventCategoryRepository.Insert(item.Id, addedCategoryIds); response.SetMessage(response.Success ? T("Event_Message_UpdateSuccessfully") : T("Event_Message_UpdateFailure")); } else { Mapper.CreateMap <EventManageModel, Event>(); item = Mapper.Map <EventManageModel, Event>(model); response = Insert(item); if (response.Success) { if (model.EventCategoryIds != null) { foreach (var categoryId in model.EventCategoryIds) { var eventEventCategory = new EventEventCategory { EventCategoryId = categoryId, EventId = item.Id }; _eventEventCategoryRepository.Insert(eventEventCategory); } } } response.SetMessage(response.Success ? T("Event_Message_CreateSuccessfully") : T("Event_Message_CreateFailure")); } return(response); }