public async Task<ActionResult> Checkout() { #region Data to Display CartActions act = new CartActions(); WishlistActions wishAct = new WishlistActions(); ApplicationDbContext dataSocket = new ApplicationDbContext(); UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(dataSocket); userMgr = new ApplicationUserManager(myStore); var thisUser = await userMgr.FindByNameAsync(User.Identity.Name); int Id = (int)thisUser.Carts.CartID; try { double nm = await GetCartTotal(Id); string[] xn = nm.ToString().Split('.'); Session["cartTotal"] = xn[0] + "," + xn[1]; } catch { Session["cartTotal"] = act.GetTotalAsync(Id); } Session["wishlistTotal"] = wishAct.GetWishlistTotal(thisUser.Wishlists.WishlistID); //List<CartItem> myItems = new List<CartItem>(); ProductViewModel myNewModel = new ProductViewModel(); IEnumerable<CartItem> myItems = act.GetCartItemsAsync(Id); if (myItems != null) { myHandler = new BusinessLogicHandler(); List<Book> ifBooks = new List<Book>(); List<Technology> ifGadget = new List<Technology>(); foreach (var item in myItems) { if (myHandler.CheckProductType(item.ProductID)) { Book book = new Book(); book = myHandler.GetBook(item.ProductID); ifBooks.Add(book); } else { Technology device = new Technology(); device = myHandler.GetTechnologyDetails(item.ProductID); ifGadget.Add(device); } } myNewModel.allBook = ifBooks; myNewModel.allCartItem = myItems.ToList(); myNewModel.allTechnology = ifGadget; List<ProductViewModel.CartHelper> itemList = new List<ProductViewModel.CartHelper>(); ProductViewModel.CartHelper cartHelp; if (myItems != null) { var revised = from rev in ifBooks join item in myItems on rev.ProductID equals item.ProductID where rev.ProductID == item.ProductID select new { rev.ProductID, rev.SellingPrice, item.Quantity }; foreach (var ite in revised) { cartHelp = new ProductViewModel.CartHelper(); cartHelp.ProductID = ite.ProductID; cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity); itemList.Add(cartHelp); } } if (myItems != null) { if (ifGadget != null) { var revised = from rev in ifGadget join item in myItems on rev.ProductID equals item.ProductID where rev.ProductID == item.ProductID select new { rev.ProductID, rev.SellingPrice, item.Quantity }; foreach (var ite in revised) { cartHelp = new ProductViewModel.CartHelper(); cartHelp.ProductID = ite.ProductID; cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity); itemList.Add(cartHelp); } } } double cartTotal = Convert.ToDouble(Session["cartTotal"].ToString()); cartTotal = cartTotal / 100; List<Company> company = myHandler.GetCompanyDetails(); double vat = 0; foreach (var item in company) { vat = item.VATPercentage; } vat = vat + 1; double subTotal = cartTotal / vat; double vatAmount = cartTotal - subTotal; ProductViewModel.CartConclude finishing = new ProductViewModel.CartConclude(); finishing.CartTotal = cartTotal; finishing.VatAddedTotal = vatAmount; finishing.SubTotal = subTotal; myNewModel.ItsA_wrap = new List<ProductViewModel.CartConclude>(); myNewModel.ItsA_wrap.Add(finishing); myNewModel.secureCart = itemList; } else { return RedirectToAction("Edit"); } #endregion #region Drop down data DeliveryHandler deliver = new DeliveryHandler(); IEnumerable<Delivery> delivery = (IEnumerable<Delivery>)deliver.GetDeliveryList(); var dataStore = from name in delivery select new { Value = name.DeliveryServiceID, Text = name.ServiceName }; ViewBag.DeliveryList = new SelectList(dataStore.ToList()); List<SelectListItem> deliveryI = new List<SelectListItem>(); deliveryI.Add(new SelectListItem { Text = "Delivery Service", Value = "", Selected = true }); foreach (var item in delivery) { deliveryI.Add(new SelectListItem { Text = item.ServiceName, Value = item.DeliveryServiceID.ToString() }); } myNewModel.I_DeliveryList = new List<SelectListItem>(); myNewModel.I_DeliveryList = deliveryI; ViewData["I_Delivery"] = deliveryI; #endregion #region Default Address if (thisUser.Address != null) { myNewModel.deliveryHelper = new DeliveryHelper(); myNewModel.deliveryHelper.DeliveryAddress = thisUser.Address; } #endregion return View(myNewModel); }
public async Task<ActionResult> Edit() { CartActions act = new CartActions(); WishlistActions wishAct = new WishlistActions(); ApplicationDbContext dataSocket = new ApplicationDbContext(); UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(dataSocket); userMgr = new ApplicationUserManager(myStore); var thisUser = await userMgr.FindByNameAsync(User.Identity.Name); int Id = (int)thisUser.Carts.CartID; try { double nm = await GetCartTotal(Id); string[] xn = nm.ToString().Split('.'); Session["cartTotal"] = xn[0] + "," + xn[1]; } catch { Session["cartTotal"] = act.GetTotalAsync(Id); } Session["wishlistTotal"] = wishAct.GetWishlistTotal(thisUser.Wishlists.WishlistID); List<CartItem> myItems = new List<CartItem>(); try { myItems = act.GetCartItemsAsync(Id).ToList();} catch(ArgumentNullException) { myItems = null; } myHandler = new BusinessLogicHandler(); List<Book> ifBooks = new List<Book>(); ProductViewModel myNewModel = new ProductViewModel(); List<Technology> ifGadget = new List<Technology>(); if (myItems != null) { foreach (var item in myItems) { if (myHandler.CheckProductType(item.ProductID)) { Book book = new Book(); book = myHandler.GetBook(item.ProductID); ifBooks.Add(book); } else { Technology device = new Technology(); device = myHandler.GetTechnologyDetails(item.ProductID); ifGadget.Add(device); } } myNewModel.allCartItem = new List<CartItem>(); myNewModel.allBook = new List<Book>(); myNewModel.allTechnology = new List<Technology>(); List<ProductViewModel.CartHelper> itemList = new List<ProductViewModel.CartHelper>(); ProductViewModel.CartHelper cartHelp; if (myItems != null) { if (ifBooks != null) { var revised = from rev in ifBooks join item in myItems on rev.ProductID equals item.ProductID where rev.ProductID == item.ProductID select new { rev.ProductID, rev.SellingPrice, item.Quantity }; foreach (var ite in revised) { cartHelp = new ProductViewModel.CartHelper(); cartHelp.ProductID = ite.ProductID; cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity); itemList.Add(cartHelp); } } } if (myItems != null) { if (ifGadget != null) { var revised = from rev in ifGadget join item in myItems on rev.ProductID equals item.ProductID where rev.ProductID == item.ProductID select new { rev.ProductID, rev.SellingPrice, item.Quantity }; foreach (var ite in revised) { cartHelp = new ProductViewModel.CartHelper(); cartHelp.ProductID = ite.ProductID; cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity); itemList.Add(cartHelp); } } } double cartTotal = Convert.ToDouble(Session["cartTotal"].ToString()); cartTotal = cartTotal / 100; List<Company> company = myHandler.GetCompanyDetails(); double vat = 0; foreach (var item in company) { vat = item.VATPercentage; } vat = vat + 1; double subTotal = cartTotal / vat; double vatAmount = cartTotal - subTotal; ProductViewModel.CartConclude finishing = new ProductViewModel.CartConclude(); finishing.CartTotal = cartTotal; finishing.VatAddedTotal = vatAmount; finishing.SubTotal = subTotal; myNewModel.allBook = ifBooks; myNewModel.allCartItem = myItems; myNewModel.allTechnology = ifGadget; myNewModel.ItsA_wrap = new List<ProductViewModel.CartConclude>(); myNewModel.ItsA_wrap.Add(finishing); myNewModel.secureCart = itemList; return View(myNewModel); } else { myNewModel.ItsA_wrap = new List<ProductViewModel.CartConclude>(); return View(myNewModel); } }