public async Task HandleAsync(StartDelivery command) { var delivery = Delivery.Create(command.DeliveryId, command.OrderId, DeliveryStatus.InProgress); delivery.AddRegistration(new DeliveryRegistration(command.Description, command.DateTime)); await _repository.AddAsync(delivery); var events = _eventMapper.MapAll(delivery.Events); await _messageBroker.PublishAsync(events.ToArray()); }
public override async Task HandleAsync(StartDelivery command) { var delivery = Delivery.Create(command.Id, command.OrderId, DeliveryStatus.InProgress); delivery.AddRegistration(new DeliveryRegistration(command.Description, command.DateTime)); await _repository.AddAsync(delivery); await PublishEventsAsync(delivery); }
private static Delivery CreateDeliveryToTest() { var customerId = Guid.NewGuid().ToString(); var deliverAddressId = Guid.NewGuid().ToString(); var date = DateTime.Now.AddDays(-1).ToUniversalTime().ToString(); var deliveryToBePlanned = Delivery.Create(customerId, deliverAddressId, date); _deliveryRepository.Add(deliveryToBePlanned); Console.WriteLine("Added Delivery to be planned"); return(deliveryToBePlanned); }
public void DeliveryIsPlannedSpecification_ShouldWork_Negative() { var deliveries = new List <Delivery>(); var delivery1 = Delivery.Create("customerID_1", "id1", "date"); var delivery2 = Delivery.Create("customerID_2", "id2", "date"); deliveries.Add(delivery1); deliveries.Add(delivery2); var specification = new DeliveryIsPlannedSpecification(); var results = deliveries.Where(specification.Criteria.Compile()).ToList(); Assert.IsNotNull(results); Assert.AreEqual(0, results.Count); }
/// <summary> /// 新增交付记录 /// </summary> /// <param name="dto">新增交付数据对象</param> public void Add(DeliveryAddDTO dto) { using (DbConnection conn = DbHelper.CreateConnection()) { DbTransaction trans = null; try { conn.Open(); trans = conn.BeginTransaction(); if (trans == null) { throw new ArgumentNullException("DbTransaction"); } #region Delivery and Cost Delivery entity = new Delivery(); entity.Create(dto.Date, dto.ExpressCompany, dto.ExpressBill, dto.IncludeOrder, dto.Summary, dto.Remark, dto.Costs, dto.Creator); this.deliveryRepository.Insert(trans, entity); foreach (Cost cost in entity.Costs) { this.costRepository.Insert(trans, cost); } #endregion Dictionary <string, Sale> sales = new Dictionary <string, Sale>(); Dictionary <string, string> items = new Dictionary <string, string>(); foreach (DeliveryDetailAddDTO detail in dto.DeliveryDetails) { #region Purchase Purchase purchase = this.purchaseRepository.Select(trans, detail.PurchaseId); if (purchase == null || purchase.Category != detail.ItemCategory || purchase.Item != detail.Item) { throw new EasySoftException(string.Format("关联的采购单不存在或项目不正确。采购单ID:{0}, 采购项:{1}", purchase.Id, detail.ItemName)); } if (purchase.Inventory < detail.DeliveryQuantity) { throw new EasySoftException(string.Format("库存不足。采购单ID:{0}, 采购项:{1}", purchase.Id, detail.ItemName)); } purchase.Delivery(detail.DeliveryQuantity, dto.Creator); this.purchaseRepository.Update(trans, purchase); #endregion #region DeliveryDetail DeliveryDetail detailEntity = new DeliveryDetail(); detailEntity.Create(entity.Id, purchase.Id, detail.ItemCategory, detail.DeliveryQuantity, detail.PackQuantity, detail.PackUnit, dto.Creator); this.deliveryDetailRepository.Insert(trans, detailEntity); #endregion } #region SaleOrder if (dto.IncludeOrder == Constant.COMMON_Y) { foreach (SaleOrderExpressDTO order in dto.SaleOrders) { SaleOrder orderEntity = this.saleOrderRepository.Select(trans, order.Id); if (orderEntity == null || orderEntity.NeedExpress == Constant.COMMON_N || orderEntity.Item != order.Item || orderEntity.Quantity != order.Quantity || orderEntity.Status != SaleOrderStatus.Ordered) { throw new EasySoftException(string.Format("关联的订单不存在或状态不正确,订单信息Id:{0}, 订单项:{1}", order.Id, order.ItemName)); } orderEntity.SentExpress(orderEntity.Id, dto.Creator); this.saleOrderRepository.Update(trans, orderEntity); } } #endregion #region Sale foreach (SaleAddDTO sale in dto.Sales) { Sale saleEntity = new Sale(); saleEntity.Create(entity.Id, sale.Item, sale.Quantity, sale.Unit, dto.Creator); this.saleRepository.Insert(trans, saleEntity); } #endregion trans.Commit(); } catch { if (trans != null) { trans.Rollback(); } throw; } } }