public async Task UpdateSupplier(SupplierInputDto input) { var Supplier = await db.Suppliers.SingleOrDefaultAsync(m => m.Id == input.SupplierId && !m.IsDelete); if (Supplier == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该供应商不存在" })) }); } Supplier.Name = input.Name; Supplier.PhoneNumber = input.PhoneNumber; Supplier.Address = input.Address; Supplier.Price = input.Price; Supplier.RawMaterialId = input.RawMaterialId; if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "更新失败" })) }); } }
/// <summary> /// 修改供应商 /// </summary> /// <param name="entity"></param> /// <returns></returns> public ServerResult <SupplierOutputDto> EditSupplier(SupplierInputDto entity) { var data = AutoMapperHelper.MapTo <Supplier>(entity); return(new ServerResult <SupplierOutputDto>() { Data = AutoMapperHelper.MapTo <SupplierOutputDto>(_supplierServer.EditSupplier(data)) }); }
public async Task AddSupplier(SupplierInputDto input) { var data = await db.Suppliers.SingleOrDefaultAsync(m => m.Name == input.Name && !m.IsDelete); if (data != null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该供应商已存在" })) }); } db.Suppliers.Add(new Supplier() { Id = IdentityManager.NewId(), Address = input.Address, PhoneNumber = input.PhoneNumber, Name = input.Name, IsDelete = false, RawMaterialId = input.RawMaterialId, Price = input.Price }); if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "添加失败" })) }); } }
public ServerResult <SupplierOutputDto> AddSupplier([FromBody] SupplierInputDto supplierInputDto) { return(_appServer.AddSupplier(supplierInputDto)); }