Beispiel #1
0
        public static void MapToBasketOrderAndUpdate(BasketOrder basketOrder)
        {
            BasketModel model = GlobalConfig.Connection.GetBasketById(basketOrder.Id);

            foreach (BasketDetailOrder bDetO in basketOrder.BasketDeatils)
            {
                if (model.BasketDetails.Where(x => x.Product.ProductID == bDetO.ProductId).ToList().Count > 0)
                {
                    BasketDetailModel bDM = model.BasketDetails.Where(x => x.Product.ProductID == bDetO.ProductId).ToList().FirstOrDefault();
                    bDM.Quantity = bDetO.quantity;
                    bDM.Price    = bDetO.quantity * bDM.Product.Price;
                    GlobalConfig.Connection.UpdateQuantityBasketDetail(bDM);
                    // update BasketModel file
                    List <BasketDetailModel> listBasketDetail = model.BasketDetails;
                    listBasketDetail.Remove(model.BasketDetails.Where(x => x.Product.ProductID == bDetO.ProductId).ToList().FirstOrDefault());
                    listBasketDetail.Add(bDM);
                    model.BasketDetails = listBasketDetail;
                    GlobalConfig.Connection.UpdateBasket(model.UpdateTotalAmountBasket());
                }
                else
                {
                    BasketDetailModel newBasketDe = new BasketDetailModel();
                    newBasketDe.Quantity = bDetO.quantity;
                    newBasketDe.Product  = bDetO.ProductId.ToString().LookupProductById();
                    newBasketDe.Price    = bDetO.quantity * newBasketDe.Product.Price;
                    newBasketDe.Time     = DateTime.Now;
                    GlobalConfig.Connection.CreateBasketDetail(newBasketDe);
                    // TODO: update BasketModel file
                    List <BasketDetailModel> listBasketDetail = model.BasketDetails;
                    listBasketDetail.Add(newBasketDe);
                    model.BasketDetails = listBasketDetail;
                    GlobalConfig.Connection.UpdateBasket(model.UpdateTotalAmountBasket());
                }
            }
        }