public Booking(Customer customer, Ticket ticket, int quantity) { Created = DateTime.Now; Status = BookingStatus.Reservation; Quantity = (quantity > 0) ? quantity : 1; Customer = customer; Ticket = ticket; TicketPrice = Ticket.Price; Event = Ticket.Event; Reference = GenerateUniqueReference(); BookingFee = ticket.BookingFee; Payments = new List<Payment>(); }
private void GetCustomerViaFacebook() { if (ViewBag.Customer == null) { if (FacebookWebContext.Current.IsAuthenticated()) { var client = new FacebookWebClient(); dynamic me = client.Get("me"); var customer = Repo.GetByFieldName<Customer>("FacebookID", me.id) ?? Repo.GetByFieldName<Customer>("Email", me.email); if (customer != null) ViewBag.Customer = customer; else { string fullname = me.name, firstname = me.name, surname = ""; firstname = firstname.Trim(); if (firstname.Contains(" ")) { firstname = fullname.Substring(0, fullname.IndexOf(" ")); surname = fullname.Substring(firstname.Length, fullname.Length - firstname.Length); } { var newCust = new Customer(me.email, firstname, surname, Bronson.Utils.Random.RandomString(5)); Repo.Save(newCust); ViewBag.Customer = newCust; AddCustomerLoginCookie(newCust); } } } } }
public ActionResult CustomerAccount(CreateCustomerPostModel model) { Ticket = Repo.GetById<Ticket>(model.ticketID); if ((Ticket == null) || (Ticket.Remaining < 1)) return RedirectToAction("SoldOut"); var existing = Repo.GetByFieldName<Customer>("Email", model.Email); if (existing != null) { ViewBag.ErrorMessage = "A user already exists with that email address"; return View(new CreateCustomerViewModel(Ticket,model)); } var cust = new Customer(model.Email, model.FirstName, model.Surname, model.Password); var valid = cust.Validate(); if(!valid.Succeeded) { ViewBag.ErrorMessage = valid.Message; return View(new CreateCustomerViewModel(Ticket, model)); } Repo.Save(cust); var booking = new Booking(cust, Ticket, 1); Repo.Save(booking); return RedirectToAction("ReservationSummary", new {id=booking.ID}); }
private void AddCustomerLoginCookie(Customer existing) { var cookie = new HttpCookie("TartsUser", existing.ID.EncryptInteger()); cookie.Expires = DateTime.Now.AddDays(1); cookie.HttpOnly = true; Response.Cookies.Add(cookie); Request.Cookies.Add(cookie); }