public async Task <IActionResult> Update([FromBody] SetUpGetDto GetDto, string Id) { try { var position = await _service.QueryByIdAsync(Id); var positions = await _service.QueryAsync(u => u.EnCode == GetDto.EnCode); if (positions.Count > 0 && position.EnCode != GetDto.EnCode) { return(Ok(new { Status = true, Message = "此编码已存在,请重新修改" })); } GetDto.Id = Id; var result = await _service.Update(GetDto); if (result > 0) { return(Ok(new { Status = true, Message = "修改成功" })); } return(Ok(new { Status = false, Message = "修改失败,请刷新后重试" })); } catch (Exception ex) { return(Ok(new { Status = false, Message = ex.ToString() })); } }
public async Task <IActionResult> Add([FromBody] SetUpGetDto GetDto) { try { var positions = await _service.QueryAsync(); var position = positions.Find(u => u.EnCode == GetDto.EnCode); if (position != null) { return(Ok(new { Status = true, Message = "此编码已存在,请重新输入" })); } var result = await _service.Insert(GetDto); if (result > 0) { return(Ok(new { Status = true, Message = "添加成功" })); } return(Ok(new { Status = false, Message = "添加失败,请刷新后重试" })); } catch (Exception ex) { return(Ok(new { Status = false, Message = ex.ToString() })); } }