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()); } } }
public ActionResult BasketDetail(int id) { BasketDetailModel basketDetailModel = new BasketDetailModel(); basketDetailModel.OrderProducts = db.OrderProducts.Include(x => x.User).Include(x => x.Product).OrderByDescending(x => x.Id).ToList(); basketDetailModel.Basket = db.Baskets.FirstOrDefault(x => x.Id == id); return(View(basketDetailModel)); }
public BasketDetailModel CreateBasketDetail(BasketDetailModel model) { List <BasketDetailModel> OrderDetails = TextConnectorProcessor.BasketDetailFile.FullFilePath().LoadFile().ConvertToBasketDetailModels(); int currentId = 1; if (OrderDetails.Count > 0) { currentId = OrderDetails.OrderByDescending(x => x.Id).First().Id + 1; } model.Id = currentId; OrderDetails.Add(model); OrderDetails.SaveToBasketDetailFile(); return(model); }
public static List <BasketDetailModel> ConvertToBasketDetailModels(this List <string> lines) { List <BasketDetailModel> outputList = new List <BasketDetailModel>(); //id,quantity,price,productId foreach (string line in lines) { string[] cols = line.Split(','); BasketDetailModel basketDetail = new BasketDetailModel(); basketDetail.Id = Int32.Parse(cols[0]); basketDetail.Quantity = Int32.Parse(cols[1]); basketDetail.Price = Decimal.Parse(cols[2]); basketDetail.Product = cols[3].LookupProductById(); basketDetail.Time = DateTime.Parse(cols[4]); outputList.Add(basketDetail); } return(outputList); }
public void UpdateQuantityBasketDetail(BasketDetailModel basketDetail) { throw new NotImplementedException(); }
public BasketDetailModel CreateBasketDetail(BasketDetailModel model) { throw new NotImplementedException(); }