public ActionResult AnonymousOrderBuyerDetailsSubmission(BuyersInfoViewModel model, string id) { try { if (ModelState.IsValid) { City c = new City(Convert.ToInt32(model.CityName)); Buyer buyer = new Buyer(model.FullName, model.PhoneNumber, model.Address, model.Email, c); HttpCookie anonymusBuyer = new HttpCookie("anonBuyer"); anonymusBuyer.Value = buyer.BuyerId.ToString(); anonymusBuyer.Expires = DateTime.Now.AddMinutes(30); Response.Cookies.Add(anonymusBuyer); int productId = Convert.ToInt32(id); if (Product.IsPrescriptionGlasses(productId)) { PrescriptionGlasses p = new PrescriptionGlasses(productId); OrderPrescriptionGlassesViewModel opvm = new OrderPrescriptionGlassesViewModel() { DiscountedPrice = decimal.Round(p.GetDiscountedPrice()).ToString(), Id = p.ProductId.ToString(), Images = p.Images, Lens = p.Lens.LensName, Name = p.Name, Price = decimal.Round(p.Price).ToString(), DeliveryCharges = decimal.Round(buyer.City.DeliverCharges).ToString(), Status = p.Quantity + " Item(s) available", Quantity = p.Quantity }; ViewBag.Message = null; return(View("OrderPrescriptionGlasses", opvm)); } else { Sunglasses s = new Sunglasses(productId); OrderSunglassesViewModel osvm = new OrderSunglassesViewModel() { DiscountedPrice = decimal.Round(s.GetDiscountedPrice()).ToString(), Id = s.ProductId.ToString(), Images = s.Images, Name = s.Name, Price = decimal.Round(s.Price).ToString(), Status = s.Quantity + " Item(s) available", DeliveryCharges = decimal.Round(buyer.City.DeliverCharges).ToString(), Quantity = s.Quantity }; ViewBag.Message = null; return(View("OrderSunglasses", osvm)); } } else { return(View("OrderAnonymous", model)); } } catch (Exception ex) { HandleErrorInfo error = new HandleErrorInfo(ex, "Cart", "AnonymousOrderBuyerDetailsSubmission"); return(RedirectToAction("Index", "Error", new { model = error })); } }
public ActionResult ViewProduct(int id, string urlRedirect) { try { ViewBag.Message = urlRedirect; ViewProductViewModel model = new ViewProductViewModel(); ViewBag.Message = urlRedirect; if (Product.IsPrescriptionGlasses(id)) { PrescriptionGlasses p = new PrescriptionGlasses(id); model.Id = p.ProductId.ToString(); model.Name = p.Name; model.Price = decimal.Round(p.Price).ToString(); model.PrimaryImage = p.PrimaryImage; model.Lens = p.Lens.LensName; model.Description = p.ProductDescription; model.DiscountedPrice = decimal.Round(p.GetDiscountedPrice()).ToString(); if (p.Quantity == 0) { model.Status = "Out of Stock"; } else { model.Status = p.Quantity + " Item(s) available"; } model.Frame = p.Frame.FrameName; model.FrameColor = p.FrameColor; model.Images = p.Images; model.IsSunglasses = false; } else if (Product.IsSunglasses(id)) { Sunglasses s = new Sunglasses(id); model.Id = s.ProductId.ToString(); model.Name = s.Name; model.Price = decimal.Round(s.Price).ToString(); model.PrimaryImage = s.PrimaryImage; model.LensColor = s.LensColor; model.Description = s.ProductDescription; model.DiscountedPrice = decimal.Round(s.GetDiscountedPrice()).ToString(); if (s.Quantity == 0) { model.Status = "Out of Stock"; } else { model.Status = s.Quantity + " Item(s) remaining"; } model.FrameColor = s.FrameColor; model.Images = s.Images; model.IsSunglasses = true; } return(View(model)); } catch (Exception ex) { HandleErrorInfo error = new HandleErrorInfo(ex, "Home", "ViewProduct"); return(RedirectToAction("Index", "Error", new { model = error })); } }
public ActionResult AddToCart(int id, string urlRedirect = null) { try { ViewBag.Message = urlRedirect; if (Product.IsSunglasses(id)) { Sunglasses s = new Sunglasses(id); OrderSunglassesViewModel osvm = new OrderSunglassesViewModel() { DeliveryCharges = decimal.Round(new Account(User.Identity.GetUserId()).Buyer.City.DeliverCharges).ToString(), DiscountedPrice = decimal.Round(s.GetDiscountedPrice()).ToString(), Id = s.ProductId.ToString(), Images = s.Images, Name = s.Name, Price = decimal.Round(s.Price).ToString(), Quantity = s.Quantity, Status = s.Quantity + " Item(s) available" }; return(View("OrderSunglasses", osvm)); } else if (Product.IsPrescriptionGlasses(id)) { PrescriptionGlasses p = new PrescriptionGlasses(id); OrderPrescriptionGlassesViewModel opvm = new OrderPrescriptionGlassesViewModel() { DeliveryCharges = decimal.Round(new Account(User.Identity.GetUserId()).Buyer.City.DeliverCharges).ToString(), DiscountedPrice = decimal.Round(p.GetDiscountedPrice()).ToString(), Id = p.ProductId.ToString(), Images = p.Images, Lens = p.Lens.LensName, Name = p.Name, Price = decimal.Round(p.Price).ToString(), Quantity = p.Quantity, Status = p.Quantity + " Item(s) available" }; return(View("OrderPrescriptionGlasses", opvm)); } return(View("Error")); } catch (Exception ex) { HandleErrorInfo error = new HandleErrorInfo(ex, "Cart", "AddToCart"); return(RedirectToAction("Index", "Error", new { model = error })); } }