public async Task <IActionResult> Checkout(ShippingDetails shippingDetails) { // Save order var shoppingCart = GetSessionShoppingCart(); if (shoppingCart == null) { return(RedirectToAction(nameof(Index))); } await ShoppingCartPersistence(shoppingCart); _orderUnitOfWork.ShippingDetails.Add(shippingDetails); await _orderUnitOfWork.Complete(); _orderUnitOfWork.Orders .Add(new Order { ShippingDetails = shippingDetails, ShoppingCart = shoppingCart, OrderDate = DateTime.Now, }); await _orderUnitOfWork.Complete(); return(RedirectToAction(nameof(Summary))); }
public async Task <ActionResult> CreateOrder([FromBody] OrderDto dto) { var res = _unitOfWork.OrderRepository.CreateOrder(dto.ProductArray, dto.CustomerId, dto.FeeId); _unitOfWork.OrderRepository.Add(res.Order); await _unitOfWork.Complete(); var productIds = res.Order.OrderProducts.Select(c => c.ProductId).ToList(); var products = new List <Product>(); foreach (var i in productIds) { var entity = await _unitOfWork.ProductRepository.Get(i); // Unnecessary data is nullified entity.OrderProducts = null; // Added new entity to the product collection products.Add(entity); } return(Ok(new { res.Order.Id, res.Order.CreationDate, res.Order.CustomerId, products })); }