Ejemplo n.º 1
0
        public ActionResult Create(Hole hole)
        {
            if (ModelState.IsValid)
            {
                db.hole.Add(hole);
                db.SaveChanges();
                CalculatePar(hole);
                CalculateLength(hole);
                return RedirectToAction("ViewHoles", new { id = hole.CourseID });
            }

            ViewBag.CourseID = new SelectList(db.course, "ID", "Name", hole.CourseID);
            return View(hole);
        }
Ejemplo n.º 2
0
 public ActionResult Edit(Hole hole)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hole).State = EntityState.Modified;
         db.SaveChanges();
         CalculatePar(hole);
         CalculateLength(hole);
         return RedirectToAction("ViewHoles", new { id = hole.CourseID });
     }
     ViewBag.CourseID = new SelectList(db.course, "ID", "Name", hole.CourseID);
     return View(hole);
 }
Ejemplo n.º 3
0
 private void CalculatePar(Hole hole)
 {
     var totalPar = (from item in db.hole
                                  where item.CourseID == hole.CourseID
                                  select item.Par).Sum();
     var course = db.course.Find(hole.CourseID);
     course.TotalPar = totalPar;
     db.SaveChanges();
 }
Ejemplo n.º 4
0
 private void CalculateLength(Hole hole)
 {
     var totalLength = (from item in db.hole
                     where item.CourseID == hole.CourseID
                     select item.Length).Sum();
     var course = db.course.Find(hole.CourseID);
     course.TotalLength = totalLength;
     db.SaveChanges();
 }