private async Task <TrolleyViewModel> CreateTrolleyViewModelFromTrolleyAsync(Trolley trolley) { var trolleyViewModel = new TrolleyViewModel { Id = trolley.Id, OwnerId = trolley.OwnerId }; foreach (var trolleyItem in trolley.Items) { var trolleyItemViewModel = new TrolleyItemViewModel { Id = trolleyItem.Id, CatalogItemId = trolleyItem.CatalogItemId, Quantity = trolleyItem.Quantity }; var catalogItem = await _catalogItemRepository.GetAsync(trolleyItem.CatalogItemId); trolleyItemViewModel.ProductId = catalogItem.ProductId; trolleyItemViewModel.ProductName = catalogItem.ProductName; trolleyItemViewModel.ProductPictureUrl = catalogItem.ProductPictureUrl; trolleyViewModel.Items.Add(trolleyItemViewModel); } return(trolleyViewModel); }
private async Task <TrolleyViewModel> CreateTrolleyViewModelFromTrolleyAsync(Trolley trolley) { var trolleyViewModel = new TrolleyViewModel { Id = trolley.Id, OwnerId = trolley.OwnerId }; foreach (var trolleyItem in trolley.Items) { var trolleyItemViewModel = new TrolleyItemViewModel { Id = trolleyItem.Id, CatalogItemId = trolleyItem.CatalogItemId, Quantity = trolleyItem.Quantity }; var catalogItem = await _catalogItemRepository.GetAsync(trolleyItem.CatalogItemId); var newItem = _manager.GetIndustry().ConvertItem(catalogItem); trolleyItemViewModel.ProductId = newItem.ProductId; trolleyItemViewModel.ProductName = newItem.ProductName; trolleyItemViewModel.ProductPictureUrl = newItem.ProductPictureUrl; trolleyItemViewModel.ProductAllergyInfo = newItem.ProductAllergyInfo; trolleyViewModel.Items.Add(trolleyItemViewModel); } return(trolleyViewModel); }
public IActionResult Index() { ViewData["TrolleyItems"] = TrolleyProxy.GetInstance().GetCurrentNumberOfItems(HttpContext.Session.Id.ToString()); var trolleyModel = new TrolleyViewModel(); var trolleyItems = TrolleyProxy.GetInstance().GetCurrentTrolleyItems(HttpContext.Session.Id); Dictionary <string, int> preDict = new Dictionary <string, int>(); foreach (var item in trolleyItems) { if (string.IsNullOrWhiteSpace(item)) { continue; } if (preDict.ContainsKey(item)) { preDict[item]++; } else { preDict.Add(item, 1); } } double total = 0.0; foreach (var key in preDict.Keys) { var wine = InventoryProxy.GetInstance().GetInventoryItem(key); trolleyModel.AddTrolleyItemToDisplay(wine, preDict[key]); total = total + (wine.WinePrice * preDict[key]); } ViewData["Total"] = String.Format("{0:N2}", total); return(View(trolleyModel)); }
public IActionResult Order(string EMail) { var trolleyModel = new TrolleyViewModel(); ViewData["CustomerEMail"] = EMail; ViewData["OrderResult"] = "Your order has gone through! We will confirm over e-mail shortly."; ViewData["OrderBool"] = true; ViewData["TrolleyItems"] = TrolleyProxy.GetInstance().GetCurrentNumberOfItems(HttpContext.Session.Id.ToString()); if (string.IsNullOrWhiteSpace(EMail)) { ViewData["OrderResult"] = "E-Mail address not valid. Please try again."; ViewData["OrderBool"] = false; } else { if (!EMail.Contains('@') || !EMail.Contains('.')) { ViewData["OrderResult"] = "E-Mail address not valid. Please try again."; ViewData["OrderBool"] = false; } } var trolleyItems = TrolleyProxy.GetInstance().GetCurrentTrolleyItems(HttpContext.Session.Id); Dictionary <string, int> preDict = new Dictionary <string, int>(); foreach (var item in trolleyItems) { if (string.IsNullOrWhiteSpace(item)) { continue; } if (preDict.ContainsKey(item)) { preDict[item]++; } else { preDict.Add(item, 1); } } double total = 0.0; foreach (var key in preDict.Keys) { var wine = InventoryProxy.GetInstance().GetInventoryItem(key); trolleyModel.AddTrolleyItemToDisplay(wine, preDict[key]); total = total + (wine.WinePrice * preDict[key]); } ViewData["Total"] = String.Format("{0:N2}", total); if ((bool)ViewData["OrderBool"] == false) { return(View(trolleyModel)); } var orderResult = PurchaseProxy.GetInstance().TryOrder(HttpContext.Session.Id, EMail); var orderArray = orderResult.Split(";"); if (orderArray[0].Equals("Success")) { ViewData["OrderBool"] = true; ViewData["OrderResult"] = orderArray[1]; ViewData["TrolleyItems"] = "0"; } else { ViewData["OrderBool"] = false; ViewData["OrderResult"] = orderArray[1]; } return(View(trolleyModel)); }