public JsonResult Manage(TagModel model, GridManagingModel manageModel) { if (ModelState.IsValid || manageModel.Operation == GridOperationEnums.Del) { return Json(_tagServices.ManageTag(manageModel.Operation, model)); } return Json(new ResponseModel { Success = false, Message = GetFirstValidationResults(ModelState).Message }); }
/// <summary> /// Manage tag /// </summary> /// <param name="operation">the operation</param> /// <param name="model">the tag model</param> /// <returns></returns> public ResponseModel ManageTag(GridOperationEnums operation, TagModel model) { ResponseModel response; Mapper.CreateMap<TagModel, Tag>(); Tag tag; switch (operation) { case GridOperationEnums.Edit: tag = _tagRepository.GetById(model.Id); tag.Name = model.Name; tag.RecordOrder = model.RecordOrder; tag.RecordActive = model.RecordActive; response = Update(tag); return response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::Tags:::Messages:::UpdateSuccessfully:::Update tag successfully.") : _localizedResourceServices.T("AdminModule:::Tags:::Messages:::UpdateNotFounded:::Update tag failed. Please try again later.")); case GridOperationEnums.Add: tag = Mapper.Map<TagModel, Tag>(model); response = Insert(tag); return response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::Tags:::Messages:::CreateSuccessfully:::Insert tag successfully.") : _localizedResourceServices.T("AdminModule:::Tags:::Messages:::CreateFailure:::Insert tag failed. Please try again later.")); case GridOperationEnums.Del: response = Delete(model.Id); return response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::Tags:::Messages:::DeleteSuccessfully:::Delete tag successfully.") : _localizedResourceServices.T("AdminModule:::Tags:::Messages:::DeleteFailure:::Delete tag failed. Please try again later.")); } return new ResponseModel { Success = false, Message = _localizedResourceServices.T("AdminModule:::Tags:::Messages:::ObjectNotFound:::Tag not is founded") }; }