Esempio n. 1
0
        public CartViewModel GetProductOrder(int id)
        {
            var list = context.ProductOrder.Where(p => p.OrderId == id);
            List <ItemOrderViewModel> listResult = new List <ItemOrderViewModel>();

            foreach (var item in list)
            {
                var productItemId      = item.ProductId;
                var productInfos       = context.Product.Where(x => x.Id == productItemId).FirstOrDefault();
                var itemOrderViewModel = new ItemOrderViewModel
                                             (item.OrderId, productInfos.Id, productInfos.Name, productInfos.Code,
                                             item.Quantity, item.UnitPrice);
                listResult.Add(itemOrderViewModel);
            }
            var cart = new CartViewModel(listResult);

            return(cart);
        }
Esempio n. 2
0
        public UpdateResponse RefreshSomeValues([FromBody] ItemOrderViewModel item)
        {
            UpdateQuantity(item);
            var cart = orderRepository.GetProductOrder(item.OrderId);

            try
            {
                var price = cart.CartList.Where(x => x.ProductId == item.ProductId)
                            .FirstOrDefault().UnitPrice;
                item.UnitPrice = price;
            }
            catch (Exception)
            {
                ;
            }

            var toUpdate = new UpdateResponse(item, cart);

            return(toUpdate);
        }
        public void UpdateQuantity(ItemOrderViewModel item)
        {
            var productOrders = context.ProductOrder.
                                Where(x => x.OrderId == item.OrderId).ToList();

            foreach (var productOrder in productOrders)
            {
                if (productOrder.ProductId == item.ProductId)
                {
                    productOrder.RefreshQuantity(item.Quantity);
                    if (productOrder.Quantity <= 0)
                    {
                        context.ProductOrder.Remove(productOrder);
                    }
                    else
                    {
                        context.ProductOrder.Update(productOrder);
                    }
                    context.SaveChanges();
                }
            }
        }
Esempio n. 4
0
 private void UpdateQuantity(ItemOrderViewModel item)
 {
     productOrderRepository.UpdateQuantity(item);
 }