public IActionResult Post(SysOfficeEditModel model) { if (!ModelState.IsValid) { return(BadRequest()); } var checkExistMessage = CheckExist(Guid.Empty, model); if (checkExistMessage.Length > 0) { return(BadRequest(new ResultHandle { Status = false, Message = checkExistMessage })); } var branch = mapper.Map <SysOfficeModel>(model); branch.UserCreated = branch.UserModified = currentUser.UserID; branch.Id = Guid.NewGuid(); branch.DatetimeCreated = branch.DatetimeModified = DateTime.Now; var hs = sysOfficeService.AddOffice(branch); var message = HandleError.GetMessage(hs, Crud.Insert); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value, Data = branch }; if (!hs.Success) { return(BadRequest(result)); } return(Ok(result)); }
private string CheckExist(Guid id, SysOfficeEditModel model) { string message = string.Empty; if (id == Guid.Empty) { if (sysOfficeService.Any(x => x.BranchNameEn == model.BranchNameEn || x.BranchNameVn == model.BranchNameVn)) { message = stringLocalizer[LanguageSub.MSG_OBJECT_DUPLICATED].Value; } } else { if (sysOfficeService.Any(x => (x.BranchNameEn == model.BranchNameEn || x.BranchNameVn == model.BranchNameVn) && x.Id != id)) { message = stringLocalizer[LanguageSub.MSG_OBJECT_DUPLICATED].Value; } } return(message); }