public async Task <IActionResult> Add([FromBody] InventoryClassGetDto 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() })); } }
public async Task <IActionResult> Update([FromBody] InventoryClassGetDto 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> GatPagerListByWhere(string keyword, string sidx, int rows = 20, int page = 1, string sord = "ASC", string Id = "") { bool isAsc = false; if (sord.ToUpper() == "ASC") { isAsc = true; } if (string.IsNullOrEmpty(sidx)) { sidx = "SordCode"; } //UserGetDto user = await _userService.QueryByIdAsync(Id); //RoleGetDto role = await _roleService.QueryByIdAsync(user.RoleId); //PagerEntity<CustomerGetDto> entity = null; //if (role.IsAdmin) //{ PagerEntity <InventoryGetDto> entity = await _service.QueryByPagesAsync(rows, page, t => t.EnCode.Contains((keyword ?? t.EnCode)) || t.FullName.Contains(keyword ?? t.FullName) || t.CusCode.Contains(keyword ?? t.CusCode), _service.Expression(sidx), isAsc); //} //else //{ // entity = await _service.QueryByPagesAsync(rows, page, // t => t.EnCode.Contains((keyword ?? t.EnCode)) || // t.FullName.Contains(keyword ?? t.FullName) && // t.UserId==Id, // _service.Expression(sidx), isAsc); //} foreach (var item in entity.Entity) { if (entity.Entity != null && entity.Entity.Count() > 0) { var customerGet = await _customerService.QueryByIdAsync(item.CusCode); InventoryClassGetDto InventoryClassGet = await _InventoryClassService.QueryByIdAsync(item.Type); item.TypeName = InventoryClassGet == null ? "" : InventoryClassGet.FullName; item.CustomerName = customerGet == null ? "" : customerGet.FullName; item.CustomerCode = customerGet == null ? "" : customerGet.EnCode; } } //设置返回格式 ReturnEntity RtEntity = new ReturnEntity(); RtEntity.rows = entity.Entity; RtEntity.page = page; RtEntity.records = entity.Total; int Count = entity.Total / rows; //获取除数 int yu = entity.Total % rows; //获取余数 if (yu > 0) //如果余数大于0则加一页,否则不加 { yu = 1; } else { yu = 0; } RtEntity.total = Count + yu; return(Ok(Extensions.ToJson(RtEntity))); }