示例#1
0
        private Preorders GetPreorder(int id)
        {
            Preorders preorder = context.Preorders
                                 .Where(c => c.Id == id)
                                 .Single();

            return(preorder);
        }
示例#2
0
        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"));
        }
示例#3
0
        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");
            }
        }
示例#4
0
        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"));
        }
示例#5
0
        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"));
        }
示例#6
0
        public ActionResult ApprovePreorder(int id)
        {
            Preorders preorder = GetPreorder(id);

            return(View(preorder));
        }
示例#7
0
        public ActionResult PreorderDelete(int id)
        {
            Preorders preorder = GetPreorder(id);

            return(View(preorder));
        }