Esempio n. 1
0
 public CreateCustomerViewModel(Ticket ticket = null, CreateCustomerPostModel postModel = null)
 {
     if (ticket != null)
     {
         EventName = ticket.Event.Name;
         EventSlug = ticket.Event.Slug;
         TicketID = ticket.ID;
         TicketName = ticket.Name;
     }
     if(postModel != null)
     {
         FirstName = postModel.FirstName;
         Surname = postModel.Surname;
         Email = postModel.Email;
     }
 }
Esempio n. 2
0
        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});
        }