public async Task <IActionResult> Update([FromBody] AreaSingleDto SingleDto, string Id) { try { var areas = await _service.QueryAsync <AreaSingleDto>(); var area = areas.Find(u => u.EnCode == SingleDto.EnCode); if (areas.Count > 0 && area.EnCode != SingleDto.EnCode) { return(Ok(new { Status = true, Message = "此编码已存在,请重新修改" })); } SingleDto.Id = Id; var result = await _service.Update(SingleDto); 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] AreaSingleDto SingleDto) { try { var areas = await _service.QueryAsync <AreaSingleDto>(); var area = areas.Find(u => u.EnCode == SingleDto.EnCode); if (area != null) { return(Ok(new { Status = true, Message = "此编码已存在,请重新输入" })); } var result = await _service.Insert(SingleDto); 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() })); } }