public JsonResult Checkout(CreditCard creditCard) { Cart cart = new Cart(); if (User.IsInRole("TelesaleStaff")) { Customer c = (Customer)System.Web.HttpContext.Current.Session["customer"]; MembershipCreateStatus createStatus; Membership.CreateUser(c.FirstName + c.LastName, "dummypassword", "", null, null, true, c.MembershipID, out createStatus); if (createStatus == MembershipCreateStatus.Success) { cart.ctx.AddToCustomers(c); } } List<string> reasons = new List<string>(); if (ModelState.IsValid)//Check if credit card is ok { var cost = cart.GetCartTotal(); List<String> booking_ids = new List<string>(); foreach (Booking b in cart.GetBookings()) { booking_ids.Add(b.id.ToString()); } if (creditCard.isValid() && creditCard.hasAmount(cost)) //confirm that the money is there { if (cart.Checkout()) { creditCard.Charge(cost); return Json(new { success = true, ids = booking_ids }); } else { return Json(new { success = false , errors = cart.WhyNotValid}); } } else { reasons.Add("We havent ben able to charge your credit card. "); return Json(new { success = false, errors = reasons }); } } else { //This means that something is not valid with the card. reasons.Add("The card details you have entered are not valid. "); return Json(new { success = false, errors = reasons }); } }
public JsonResult AddPassengers(Passanger passenger) { if (ModelState.IsValid) { Cart cart = new Cart(); Booking booking = cart.GetBookings().SingleOrDefault(b => b.travel_id == passenger.travel_id); Passanger existing_passenger = booking.Travel.Passangers.SingleOrDefault(p => p.id == passenger.id); //existing_passenger = passenger; existing_passenger.first_name = passenger.first_name; existing_passenger.last_name = passenger.last_name; existing_passenger.passaport_no = passenger.passaport_no; String nextpage = "/Booking/Payments"; if (booking.customer_id == Guid.Parse("00000000-0000-0000-0000-000000000000"))//dummy id { nextpage = "/Account/Register"; } return Json(new { success = true, id = existing_passenger.id , nextpage = nextpage}); } return Json(new { success = false }); }
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); }