Esempio n. 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            CourseOccasion courseOccasion = db.CourseOccasions.Find(id);
            int            GroupNr        = (int)courseOccasion.GroupId;

            db.CourseOccasions.Remove(courseOccasion);
            db.SaveChanges();
            return(RedirectToAction("Details/" + GroupNr, "Groups"));
            //return RedirectToAction("Index");
        }
Esempio n. 2
0
        // GET: Skapar en sida med detaljer för kursen
        public ActionResult Details(int?id, int?id2)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CourseOccasion courseOccasion = db.CourseOccasions.Find(id);

            if (courseOccasion == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Line3            = " Till ";
            ViewBag.courseOccasionId = id;
            ViewBag.groupId          = id2;
            return(View(courseOccasion));
        }
Esempio n. 3
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CourseOccasion courseOccasion = db.CourseOccasions.Find(id);

            if (courseOccasion == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Line1 = "/";
            ViewBag.Line2 = "-";
            ViewBag.Line3 = " Till ";
            return(View(courseOccasion));
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,StartDate,EndDate,GroupId")] CourseOccasion courseOccasion)
        {
            if (ModelState.IsValid)
            {
                DateTime GroupsStartDate = db.Groups.Where(g => g.Id == courseOccasion.GroupId).FirstOrDefault().StartDate;
                DateTime GroupsEndDate   = db.Groups.Where(g => g.Id == courseOccasion.GroupId).FirstOrDefault().EndDate;

                if (courseOccasion.StartDate < GroupsStartDate)
                {
                    //AddErrors(ModelState);
                    ViewBag.GroupId = courseOccasion.GroupId;
                    ModelState.AddModelError("", "Du har angivit ett startdatumet före gruppens startdatumet");
                    return(View(courseOccasion));
                }

                else if (courseOccasion.EndDate > GroupsEndDate)
                {
                    //AddErrors(ModelState);
                    ViewBag.GroupId = courseOccasion.GroupId;
                    ModelState.AddModelError("", "Du har angivit ett slutdatum efter gruppens slutdatum");
                    return(View(courseOccasion));
                }

                else if (courseOccasion.StartDate > courseOccasion.EndDate)
                {
                    //AddErrors(ModelState);
                    ViewBag.GroupId = courseOccasion.GroupId;
                    ModelState.AddModelError("", "Du har angivit ett slutdatum före startdatumet ");
                    return(View(courseOccasion));
                }

                else
                {
                    db.CourseOccasions.Add(courseOccasion);
                    db.SaveChanges();
                    return(RedirectToAction("Details/" + (int)courseOccasion.GroupId, "Groups"));
                }
            }
            ViewBag.GroupId = courseOccasion.GroupId;
            return(View(courseOccasion));
        }