public ActionResult Create(String name, String description, String price) { Customer c = getCurrentUser(); if (c != null && c.isAdmin) { ScarfItem scarf = new ScarfItem(); bool error = false; if (name == null || name.Equals("")) { Console.Out.WriteLine("name is null or empty"); ViewBag.ErrorName = "name is required"; error = true; } else { scarf.name = name; } if (description == null || description.Equals("")) { ViewBag.ErrorDescription = "description is required"; error = true; } else { scarf.description = description; } if (price == null || price.Equals("")) { ViewBag.ErrorPrice = "price is required"; error = true; } else { try { scarf.price = decimal.Parse(price); } catch (Exception e) { ViewBag.ErrorPrice = e.Message; error = true; } } if (error) { ViewBag.Error = "Please fill out all required fields"; return View(scarf); } else { // Insert the data and return to the Index view service.addScarf(scarf); IEnumerable<ScarfItem> scarves = service.getAllScarves(); Customer customer = getCurrentUser(); var CandP = new CustomerAndProducts(); CandP.Customer = customer; CandP.Cart = service.getCustomerCart(customer); CandP.Scarves = scarves; return View("Index", CandP); } } else { TempData["GlobalError"] = "You are not Authorized to access the requested page"; return RedirectToAction("Index", "Home"); } }
public ActionResult Index(long scarfId) { Customer c = getCurrentUser(); ScarfOrder currentCart; if (c == null) { // set an error message and return to view ViewBag.Error = "Please Login to add items to your cart!"; currentCart = service.EmptyCart(); } else { // user is logged in, lets add this item to their cart... currentCart = service.getCustomerCart(c); ScarfItem scarf = service.getScarf(scarfId); currentCart.Scarves.Add(scarf); service.updateOrder(currentCart); /* currentCart = service.EmptyCart(c); ScarfItem scarf = service.getScarf(scarfId); currentCart.Scarves.Add(scarf); service.addOrder(currentCart); */ } var CandP = new CustomerAndProducts(); CandP.Customer = c; CandP.Scarves = service.getAllScarves(); CandP.Cart = currentCart; return View(CandP); }
public ActionResult Scarf(int id) { Customer customer = getCurrentUser(); ScarfItem scarf = service.getScarf(id); var CandP = new CustomerAndProducts(); CandP.Customer = customer; ScarfOrder s = service.getCustomerCart(customer); CandP.Cart = s; CandP.Scarves = new ScarfItem[]{scarf}; return View(CandP); }
public ActionResult Index() { IEnumerable<ScarfItem> scarves = service.getAllScarves(); Customer customer = getCurrentUser(); var CandP = new CustomerAndProducts(); CandP.Customer = customer; ScarfOrder s = service.getCustomerCart(customer); CandP.Cart = s; CandP.Scarves = scarves; return View(CandP); }