/// <summary> /// Save location type /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveLocationType(LocationTypeManageModel model) { ResponseModel response; var locationType = GetById(model.Id); if (locationType != null) { locationType.Name = model.Name; locationType.PinImage = model.PinImage; locationType.RecordOrder = model.RecordOrder; response = Update(locationType); return(response.SetMessage(response.Success ? T("LocationType_Message_UpdateSuccessfully") : T("LocationType_Message_UpdateFailure"))); } Mapper.CreateMap <LocationTypeManageModel, LocationType>(); locationType = Mapper.Map <LocationTypeManageModel, LocationType>(model); response = Insert(locationType); return(response.SetMessage(response.Success ? T("LocationType_Message_CreateSuccessfully") : T("LocationType_Message_CreateFailure"))); }
public ActionResult PopupEdit(LocationTypeManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _locationTypeService.SaveLocationType(model); SetResponseMessage(response); if (response.Success) { switch (submit) { case SubmitType.PopupSave: return(View("CloseFancyBox", new CloseFancyBoxViewModel { IsReload = false, ReturnUrl = string.Empty })); case SubmitType.SaveAndContinueEdit: return(RedirectToAction("PopupEdit", new { id = model.Id })); } } } SetupPopupAction(); return(View(model)); }
/// <summary> /// Update value for property of model /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel UpdateLocationTypeData(XEditableModel model) { var locationType = GetById(model.Pk); if (locationType != null) { var property = ReflectionUtilities.GetAllPropertiesOfType(typeof(LocationTypeManageModel)) .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 LocationTypeManageModel(locationType); manageModel.SetProperty(model.Name, value); var validationResults = manageModel.ValidateModel(); if (validationResults.Any()) { return(new ResponseModel { Success = false, Message = validationResults.BuildValidationMessages() }); } #endregion locationType.SetProperty(model.Name, value); var response = Update(locationType); return(response.SetMessage(response.Success ? T("LocationType_Message_UpdateLocationTypeInfoSuccessfully") : T("LocationType_Message_UpdateLocationTypeInfoFailure"))); } return(new ResponseModel { Success = false, Message = T("LocationType_Message_PropertyNotFound") }); } return(new ResponseModel { Success = false, Message = T("LocationType_Message_ObjectNotFound") }); }
public ActionResult Create(LocationTypeManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _locationTypeService.SaveLocationType(model); SetResponseMessage(response); if (response.Success) { var id = (int)response.Data; switch (submit) { case SubmitType.Save: return(RedirectToAction("Index")); default: return(RedirectToAction("Edit", new { id })); } } } return(View(model)); }
public ActionResult Edit(LocationTypeManageModel model, string returnUrl, SubmitType submit) { if (ModelState.IsValid) { var response = _locationTypeService.SaveLocationType(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)); }