public IActionResult Register(string email, string password, DateTime dob, string phone, string name, string address) { string method = HttpContext.Request.Method; if (method == "GET") { return(View()); } var errors = new List <string>(); // TODO: validation if (email == null) { errors.Add("Email must not be empty"); } else if (!IsValidEmail(email)) { errors.Add("Email address wrong format"); } else if (context.Customers.Find(email) != null) { errors.Add("Your email has been signed up"); } if (dob == null) { errors.Add("Date of birth must not be empty"); } if (phone == null) { errors.Add("Phone must not be empty"); } else if (!IsValidPhone(phone)) { errors.Add("Phone must be 10 digits long"); } if (name == null) { errors.Add("Name must not be empty"); } if (password == null) { errors.Add("Password must not be empty"); } else if (password.Length < 8) { errors.Add("Password must be at least 8 characters"); } if (errors.Count == 0) { Customer c = new Customer { email = email, password = hashStringSHA256(password), dob = dob, phone = phone, name = name, address = address }; context.Add(c); context.SaveChanges(); TempData["msgresponse"] = "Successfully create new account. Let's login!"; return(Redirect("/Customer/Login")); } ViewBag.errors = errors; ViewData["email"] = email; ViewData["password"] = password; ViewData["dob"] = dob.ToString("yyyy-MM-dd"); ViewData["phone"] = phone; ViewData["name"] = name; ViewData["address"] = address; return(View()); }
public int Complete() { return(context.SaveChanges()); }
public IActionResult BookTicketConfirmed(int id, [FromForm] string[] selected_items) { Customer cus = null; if (!Auth.isAuth(HttpContext, ref cus)) { return(Unauthorized()); } ViewBag.customer = cus; var ms = context.MovieShows .Include(x => x.tickets) .ThenInclude(x => x.Seat) .Where(x => x.id == id) .FirstOrDefault(); if (ms == null) { return(NotFound()); } var ordered_seats = new HashSet <KeyValuePair <int, int> >(); ms.tickets.ToList().ForEach(x => { ordered_seats.Add(new KeyValuePair <int, int>(x.Seat.r, x.Seat.c)); }); if (selected_items != null) { foreach (var item in selected_items) { int r = int.Parse(item.Split("-")[0]); int c = int.Parse(item.Split("-")[1]); if (!ordered_seats.Contains(new KeyValuePair <int, int>(r, c))) { Seat s = context.Seat .Where(x => x.r == r && x.c == c && x.theaterid == ms.theaterid) .FirstOrDefault(); if (s == null) { return(NotFound()); } Ticket t = new Ticket { seatid = s.id, email = cus.email, movieshowid = ms.id }; context.Add(t); } } } TempData["msgresponse"] = "Your tickets has been saved"; context.SaveChanges(); return(RedirectToAction(nameof(ListTickets))); }