Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Name,Email")] Driver driver)
        {
            if (ModelState.IsValid)
            {
                db.Drivers.Add(driver);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(driver));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Name")] SiblingGroup siblingGroup)
        {
            if (ModelState.IsValid)
            {
                db.SiblingGroups.Add(siblingGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(siblingGroup));
        }
        public ActionResult Create([Bind(Include = "Id,SiblingId,Busydate")] UnavailableDate unavailableDate)
        {
            if (ModelState.IsValid)
            {
                db.UnavailableDates.Add(unavailableDate);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SiblingId = new SelectList(db.Siblings, "Id", "FirstName", unavailableDate.SiblingId);
            return(View(unavailableDate));
        }
        public ActionResult Create([Bind(Include = "Id,GroupId,FirstName,LastName,Address,PhoneNumber,Email")] Sibling sibling)
        {
            if (ModelState.IsValid)
            {
                db.Siblings.Add(sibling);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.GroupId = new SelectList(db.SiblingGroups, "Id", "Name", sibling.GroupId);
            return(View(sibling));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Id,VisitStart,VisitEnd,DriverId")] Visit visit)
        {
            var userid  = User.Identity.GetUserId();
            var sibling = db.Siblings.Find(userid);
            var IsValid = ModelState.IsValid;

            if (IsValid && visit.VisitStart.Date != visit.VisitEnd.Date)
            {
                IsValid = false;
                ModelState.AddModelError("VisitEnd", "Visit Must Start and End on The Same Day");
            }
            if (IsValid && visit.VisitStart > visit.VisitEnd)
            {
                IsValid = false;
                ModelState.AddModelError("VisitEnd", "Visit End Date Is Prior Vist STart Date");
            }
            if (IsValid)
            {
                var UnavailableDates = sibling.SiblingGroup.Siblings.SelectMany(S => S.UnavailableDates).Select(D => D.Busydate);
                if (UnavailableDates.Any(D => D == visit.VisitStart.Date))
                {
                    IsValid = false;
                    ModelState.AddModelError("VisitStart", "Date is Not Available");
                }
            }
            if (IsValid)
            {
                var SiblingGroupId = sibling.GroupId;
                visit.GroupId = SiblingGroupId;
                db.Visits.Add(visit);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DriverId = new SelectList(db.Drivers, "Id", "Name", visit.DriverId);
            ViewBag.GroupId  = new SelectList(db.SiblingGroups, "Id", "Name", visit.GroupId);
            return(View(visit));
        }