public ActionResult Register([Bind(Include = "UserId,Email,Password,Forename,Surname,Address,Phone,PostCode,Country")] User user) { userRegistration.Country = Country_PM.GetCountries(); if (ModelState.IsValid) { userPM.AddUser(user); Session["UserID"] = user.UserId.ToString(); Session["Name"] = user.Forename.ToString(); if (Session[UserIDKey] != null) { int userId = Convert.ToInt32(Session[UserIDKey]); Cart_PM.MigrateCart(userId); } return(RedirectToAction("Index", "Home")); } return(View(userRegistration)); }
public ActionResult Checkout() { Checkout checkout = new Checkout(); int userId = Convert.ToInt32(Session["UserId"]); if (Session["UserId"] == null) { return(RedirectToAction("Login", "Users")); } var items = ModelContext.Carts .Where(c => c.UserId == userId) .Count(); // redirect to carts page if no items in shopping cart if (items <= 0) { return(RedirectToAction("Cart")); } checkout.User = ModelContext.Users.Find(userId); ViewBag.Forename = checkout.User.Forename; ViewBag.Surname = checkout.User.Surname; ViewBag.Address = checkout.User.Address; ViewBag.PostCode = checkout.User.PostCode; ViewBag.Phone = checkout.User.Phone; checkout.Cart = ModelContext.Carts .Include(c => c.Product) .Include(c => c.User) .Where(c => c.UserId == userId) .ToList(); checkout.Orders = new List <Order> { new Order { FirstName = checkout.User.Forename, LastName = checkout.User.Surname, Address = checkout.User.Address, Country = checkout.User.Country, PostCode = checkout.User.PostCode } }; checkout.Product = (from d in ModelContext.Products join f in ModelContext.Carts on d.ProductId equals f.ProductId select d).ToList(); checkout.CountryList = Country_PM.GetCountries(); return(View(checkout)); }
// GET: Users/Edit/5 public ActionResult EditProfile(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } userRegistration.User = ModelContext.Users.Find(id); userRegistration.Country = Country_PM.GetCountries(); if (userRegistration.User == null) { return(HttpNotFound()); } return(View(userRegistration)); }
public ActionResult UserProfile() { AccountProfile accountProfile = new AccountProfile(); if (Session["UserId"] != null) { accountProfile.User = ModelContext.Users.Find(UserIdSession); } else { return(RedirectToAction("Login", "Users")); } accountProfile.Orders = ModelContext.Orders.Where(o => o.UserId == UserIdSession); accountProfile.Products = (from p in ModelContext.Products join o in ModelContext.Orders on p.ProductId equals o.ProductId select p); accountProfile.ProductImage = (from p in ModelContext.ProductImages join o in ModelContext.Orders on p.ProductId equals o.ProductId where p.IsDefaultImage == true select p); accountProfile.CountryList = Country_PM.GetCountries().FirstOrDefault(); accountProfile.CountryList = (from c in Country_PM.GetCountries() join u in ModelContext.Users on c.CountryID equals u.Country where u.UserId == UserIdSession select c).FirstOrDefault(); return(View(accountProfile)); }
// GET: Users/Create public ActionResult Register() { userRegistration.Country = Country_PM.GetCountries(); return(View(userRegistration)); }