public ActionResult Create(RotatingImageManageModel model, SubmitTypeEnums submit) { if (ModelState.IsValid) { var response = _rotatingImageServices.SaveRotatingImage(model); if (response.Success) { var rotatingImageId = (int)response.Data; SetSuccessMessage(response.Message); switch (submit) { case SubmitTypeEnums.Save: return RedirectToAction("Index"); default: return RedirectToAction("Edit", new { id = rotatingImageId }); } } SetErrorMessage(response.Message); } model.Groups = _rotatingImageGroupServices.GetRotatingImageGroups(); return View(model); }
/// <summary> /// Save rotating image /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveRotatingImage(RotatingImageManageModel model) { ResponseModel response; var rotatingImage = GetById(model.Id); if (rotatingImage != null) { rotatingImage.ImageUrl = model.ImageUrl; rotatingImage.Text = model.Text; rotatingImage.Url = model.Url; rotatingImage.GroupId = model.GroupId; response = Update(rotatingImage); return response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::RotatingImages:::Messages:::UpdateSuccessfully:::Update rotating image successfully.") : _localizedResourceServices.T("AdminModule:::RotatingImages:::Messages:::UpdateFailure:::Update rotating image failed. Please try again later.")); } Mapper.CreateMap<RotatingImageManageModel, RotatingImage>(); rotatingImage = Mapper.Map<RotatingImageManageModel, RotatingImage>(model); rotatingImage.RecordOrder = Fetch(i => i.GroupId == model.GroupId).Any() ? Fetch(i => i.GroupId == model.GroupId).Max(i => i.RecordOrder) + 1 : 0; response = Insert(rotatingImage); return response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::RotatingImages:::Messages:::CreateSuccessfully:::Create rotating image successfully.") : _localizedResourceServices.T("AdminModule:::RotatingImages:::Messages:::CreateFailure:::Create rotating image failed. Please try again later.")); }