private Preorders GetPreorder(int id) { Preorders preorder = context.Preorders .Where(c => c.Id == id) .Single(); return(preorder); }
public ActionResult PreorderDelete(Preorders preorder) { Preorders preorderDb = context.Preorders.Where(c => c.Id == preorder.Id).Single(); Courses courseDb = context.Courses.Where(c => c.Id == preorderDb.CourseId).Single(); courseDb.CurrentAttendants--; context.Preorders.Remove(preorderDb); context.SaveChanges(); SetFlash("success", "You have successfully deleted preorder!"); return(RedirectToAction("Preorders")); }
private void ValidatePreorder(Preorders preorder) { if (string.IsNullOrWhiteSpace(preorder.FirstName)) { ModelState.AddModelError("FirstName", "This field can't be empty"); } else if (!(preorder.FirstName.Length >= 3 && preorder.FirstName.Length <= 50)) { ModelState.AddModelError("FirstName", "Name has to be between 3 and 50 characters long"); } if (string.IsNullOrWhiteSpace(preorder.LastName)) { ModelState.AddModelError("LastName", "This field can't be empty"); } else if (!(preorder.LastName.Length >= 2 && preorder.LastName.Length <= 50)) { ModelState.AddModelError("LastName", "Last name has to be between 2 and 50 characters long"); } if (string.IsNullOrWhiteSpace(preorder.Address)) { ModelState.AddModelError("Address", "This field can't be empty"); } else if (preorder.Address.Length > 30) { ModelState.AddModelError("Address", "Address has to be under 50 characters long"); } if (string.IsNullOrWhiteSpace(preorder.Email)) { ModelState.AddModelError("Email", "This field can't be empty"); } if (string.IsNullOrWhiteSpace(preorder.Phone)) { ModelState.AddModelError("Phone", "This field can't be empty"); } else if (!(IsPhoneNumber(preorder.Phone))) { ModelState.AddModelError("Phone", "Not supported phone format"); } }
public ActionResult SignUp(Preorders preorder, int courseId) { ValidatePreorder(preorder); if (!ModelState.IsValid) { TempData["ViewData"] = ViewData; return(RedirectToAction("SignUp", new { id = courseId })); } preorder.SignUpDate = DateTime.Today; preorder.CourseId = courseId; preorder.IsApproved = false; context.Preorders.Add(preorder); context.SaveChanges(); SetFlash("success", "You have signed up for course! Your data is stored. We will contact you soon."); return(RedirectToAction("Index")); }
public ActionResult ApprovePreorder(Preorders preorder) { Preorders preorderDb = context.Preorders.Where(c => c.Id == preorder.Id).Single(); Courses courseDb = context.Courses.Where(c => c.Id == preorderDb.CourseId).Single(); preorderDb.IsApproved = !preorderDb.IsApproved; if ((bool)preorderDb.IsApproved) { courseDb.CurrentAttendants++; } else { courseDb.CurrentAttendants--; } context.SaveChanges(); SetFlash("success", "You have successfully modified preorder!"); return(RedirectToAction("Preorders")); }
public ActionResult ApprovePreorder(int id) { Preorders preorder = GetPreorder(id); return(View(preorder)); }
public ActionResult PreorderDelete(int id) { Preorders preorder = GetPreorder(id); return(View(preorder)); }