public async Task <IActionResult> Post([FromBody] Delivery delivery) { delivery.TotalPrice = delivery.Items.Sum(i => i.Quantity * i.Price); delivery.Id = await _deliveryRepository.AddAsync(delivery); return(CreatedAtAction(nameof(GetById), new { id = delivery.Id }, delivery)); }
/// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Delivery> Handle(AddDeliveryCommand command, CancellationToken cancellationToken) { DeliveryRequest request = command.Delivery; Delivery delivery = new Delivery(request.NotificationKey, request.SubscriptionKey, request.ScheduledOn); delivery = await _deliveryRepository.AddAsync(delivery); await _deliveryRepository.UnitOfWork.SaveEntitiesAsync(); return(delivery); }