public ActionResult <CommonResponeModel> Create(CategorySaveChangeRequestModel request) { var result = 0; var model = request.MapTo <Category>(); model.InitBeforeSave(RequestUsername, InitType.Create); if (string.IsNullOrEmpty(model.Code)) { var code = this.entityCenterRepository.GetCodeByEntity(nameof(Candidate)); if (string.IsNullOrEmpty(code)) { Result = new ErrorResult(ActionType.Insert, AppGlobal.MakeCodeError); return(GetCommonRespone()); } model.Code = code; } result = this.categoryRepository.Insert(model); if (result > 0) { Result = new SuccessResult(ActionType.Insert, AppGlobal.SaveChangeSuccess); } else { Result = new ErrorResult(ActionType.Insert, AppGlobal.SaveChangeFalse); } return(GetCommonRespone()); }
public ActionResult <CommonResponeModel> Update(CategorySaveChangeRequestModel request) { var result = 0; var model = request.MapTo <Category>(); var currentObj = this.categoryRepository.GetById(model.Id); if (currentObj != null) { model.InitBeforeSave(RequestUsername, InitType.Update); result = this.categoryRepository.Update(model); } else { Result = new ErrorResult(ActionType.Select, CommonMessageGlobal._404); } if (result > 0) { Result = new SuccessResult(ActionType.Insert, AppGlobal.SaveChangeSuccess); } else { Result = new ErrorResult(ActionType.Insert, AppGlobal.SaveChangeFalse); } return(GetCommonRespone()); }
public ActionResult <CommonResponeModel> SaveChange(CategorySaveChangeRequestModel request) { var model = request.MapTo <Category>(); int result = 0; if (model.Id > 0) { model.InitBeforeSave(RequestUsername, InitType.Update); result = this.categoryRepository.Update(model); } else { model.InitBeforeSave(RequestUsername, InitType.Create); if (string.IsNullOrEmpty(model.Code)) { var code = this.entityCenterRepository.GetCodeByEntity(nameof(Category)); if (string.IsNullOrEmpty(code)) { Result = new ErrorResult(ActionType.Insert, AppGlobal.MakeCodeError); return(GetCommonRespone()); } model.Code = code; } if (this.categoryRepository.IsExistEntityWithCode("Category", model.Code, out Category category) == true) { Result = new ErrorResult(ActionType.Insert, AppGlobal.ExistCodeError); return(GetCommonRespone()); } result = this.categoryRepository.Insert(model); } if (result > 0) { Result = new SuccessResult(ActionType.Edit, AppGlobal.SaveChangeSuccess); } else { Result = new ErrorResult(ActionType.Edit, AppGlobal.SaveChangeFalse); } return(GetCommonRespone()); }