/// <summary> /// 新增订单 /// </summary> /// <param name="date">日期</param> /// <param name="item">产品项</param> /// <param name="unit">单位</param> /// <param name="price">单价</param> /// <param name="quantity">数量</param> /// <param name="actualAmount">实收金额</param> /// <param name="needExpress">需要快递</param> /// <param name="remark">备注</param> /// <param name="addressId">客户地址Id</param> /// <param name="creator">创建人</param> public void Insert(DateTime date, string item, string unit, decimal price, decimal quantity, decimal actualAmount, string needExpress, string remark, string addressId, string creator) { using (DbConnection conn = DbHelper.CreateConnection()) { DbTransaction trans = null; try { conn.Open(); trans = conn.BeginTransaction(); if (trans == null) { throw new ArgumentNullException("DbTransaction"); } CustomerAddress customerAddress = this.customerAddressRepository.Select(trans, addressId); if (customerAddress == null) { throw new EasySoftException(BusinessResource.SaleOrder_CustomerAddressInvalid); } SaleOrder entity = new SaleOrder(); entity.Create(date, customerAddress.CustomerId, customerAddress.Address, customerAddress.Mobile, customerAddress.Linkman, item, quantity, unit, needExpress, price, actualAmount, remark, creator); this.saleOrderRepository.Insert(trans, entity); trans.Commit(); } catch { if (trans != null) { trans.Rollback(); } throw; } } }
public void Insert(SaleOrderAddDTO dto) { using (DbConnection conn = DbHelper.CreateConnection()) { DbTransaction trans = null; try { conn.Open(); trans = conn.BeginTransaction(); if (trans == null) { throw new ArgumentNullException("DbTransaction"); } foreach (SaleOrderDetailAddDTO detail in dto.SaleOrderDetails) { SaleOrder entity = new SaleOrder(); entity.Create(dto.Date, detail.CustomerId, detail.Address, detail.Mobile, detail.Linkman, dto.Item, dto.Quantity, dto.Unit, detail.NeedExpress, dto.Price, 0, dto.Remark, dto.Creator); this.saleOrderRepository.Insert(trans, entity); } trans.Commit(); } catch { if (trans != null) { trans.Rollback(); } throw; } } }
/// <summary> /// 新增销售订单 /// </summary> /// <returns></returns> public ActionResult Create() { string CompanyID = WebUtil.GetFormValue <string>("CompanyID", string.Empty); SaleOrderEntity entity = WebUtil.GetFormObject <SaleOrderEntity>("Entity"); List <SaleDetailEntity> list = WebUtil.GetFormObject <List <SaleDetailEntity> >("List"); entity.SnNum = ConvertHelper.NewGuid(); entity.AuditeStatus = (int)EAudite.Wait; entity.Status = (int)EOrderStatus.CreateOrder; entity.IsDelete = (int)EIsDelete.NotDelete; entity.CreateTime = DateTime.Now; entity.CompanyID = entity.CompanyID.IsEmpty() ? CompanyID : entity.CompanyID; Bill <SaleOrderEntity, SaleDetailEntity> bill = new SaleOrder(CompanyID); string returnValue = bill.Create(entity, list); DataResult result = new DataResult(); if (EnumHelper.GetEnumDesc <EReturnStatus>(EReturnStatus.Success) == returnValue) { result.Code = (int)EResponseCode.Success; result.Message = "销售订单创建成功"; } else { result.Code = (int)EResponseCode.Exception; result.Message = "销售订单创建失败"; } return(Content(JsonHelper.SerializeObject(result))); }
void SaleMgrSeed(AlpsContext context) { var quantity = 100; foreach (var sku in context.ProductSkus) { context.Commodities.Add(Commodity.Create(sku.ID, sku.FullName, sku.Description, 3800, quantity * 3, quantity++)); } context.SaveChanges(); var saleOrder = SaleOrder.Create(customerID); // foreach (var commodity in context.Commodities.Take(5)) // { // saleOrder.AddItem(commodity.ID, 12, 2000, 5, "#"); // } foreach (var productSku in context.ProductSkus.Take(5)) { saleOrder.AddItem(productSku.ID, productSku.Name, 12, 2000, 5, "#"); } context.SaleOrders.Add(saleOrder); saleOrder = SaleOrder.Create(customerID); foreach (var productSku in context.ProductSkus.OrderByDescending(p => p.ID).Take(5)) { saleOrder.AddItem(productSku.ID, productSku.Name, 1, 3000, 1, "#"); } // foreach (var commodity in context.Commodities.OrderByDescending(p => p.ID).Take(5)) // { // saleOrder.AddItem(commodity.ID, 1, 3000, 1, "#"); // } context.SaleOrders.Add(saleOrder); context.SaveChanges(); }
public async Task <IActionResult> PostSaleOrder([FromBody] SaleOrderEditDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var saleOrder = SaleOrder.Create(dto.CustomerID); saleOrder.UpdateItems(dto.Items); _context.SaleOrders.Add(saleOrder); await _context.SaveChangesAsync(); return(this.AlpsActionOk()); }