protected override void Initialize(System.Web.Routing.RequestContext requestContext) { Cart cart = new Cart(); if (cart.isEmpty()) requestContext.HttpContext.Response.Redirect("/home/"); base.Initialize(requestContext); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { Guid userKey = Guid.NewGuid(); // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, userKey, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); // Attempt to create Customer Customer c = new Customer();//model.FirstName, model.LastName, model.Address, model.PostCode, model.TelephoneNumber, model.PassportNumber, userKey); c.FirstName = model.FirstName; c.LastName = model.LastName; c.Address = model.Address; c.PostCode = model.PostCode; c.TelephoneNumber = model.TelephoneNumber; c.PassportNumber = model.PassportNumber; c.MembershipID = userKey; c.AddCustomer(); Cart cart = new Cart(); if(cart.isEmpty()){ return RedirectToAction("Index", "Home"); } else{//customers was just shppping now foreach (Booking b in cart.GetBookings()) { b.customer_id = c.MembershipID; return RedirectToAction("Payments", "Booking"); } } } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }