public async Task <Order> CreateOrderAsync(string buyerEmail, int deliveryMethodId, string basketId, Address shippingAddress) { var basket = await _bskrepo.GetBasketAsync(basketId); var orderItems = new List <OrderItem>(); foreach (var item in basket.Items) { var product = await _uow.Repository <Product>().GetByIdAsync(item.Id); var productItemOrdered = new ProductItemOrdered(product.Id, product.Name, product.PhotoUrl); orderItems.Add(new OrderItem(productItemOrdered, product.Price, item.Quantity)); } var order = new Order(orderItems, buyerEmail, orderItems.Sum(x => x.Price * x.Quantity), shippingAddress, await _uow.Repository <DeliveryMethod>().GetByIdAsync(deliveryMethodId)); _uow.Repository <Order>().Add(order); var result = await _uow.Complete(); if (result <= 0) { return(null); } await _bskrepo.DeleteBasketAsync(basketId); return(order); }
public async Task <ActionResult <bool> > DeleteBasketAsync(string id) { return(Ok(await _repo.DeleteBasketAsync(id))); }
public async Task DeleteBasket([FromQuery] string id) { await _basketRepo.DeleteBasketAsync(id); }