public async Task <IResultModel> Add(PositionAddModel model) { var entity = _mapper.Map <PositionEntity>(model); if (await _repository.Exists(entity)) { return(ResultModel.Failed("岗位名称或编码已存在")); } var result = await _repository.AddAsync(entity); return(ResultModel.Result(result)); }
public async Task <ActionResult <Position> > PostPosition([FromForm] Position position) { await _position.AddAsync(position); try { await _position.CommitAsync(); } catch (Exception) { return(BadRequest(new { errors = new[] { "При добавлении произошла ошибка" } })); } await _authService.AddRole(position.Name); return(StatusCode(201, new { message = "Должность добавлена" })); }
public async Task <IResultModel> Add(PositionAddModel model) { var entity = _mapper.Map <PositionEntity>(model); if (await _repository.ExistsName(entity.Name)) { return(ResultModel.Failed("名称已存在")); } if (entity.Code.NotNull() && await _repository.ExistsCode(entity.Code)) { return(ResultModel.Failed("名称已存在")); } var result = await _repository.AddAsync(entity); return(ResultModel.Result(result)); }