예제 #1
0
 // GET: /MonitorBeurt/Details/5
 public ActionResult Details(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     
     var reservatie = from m in db.Reservatie
                      where m.ToezichtbeurtId == id
                          select m;
     ReservatieModel res = new ReservatieModel();
     MonitorBeurtModel monitorbeurtmodel = db.MonitorBeurt.Find(id);
     if (monitorbeurtmodel == null)
     {
         return HttpNotFound();
     }
     var tuple = new Tuple<MonitorBeurtModel,ReservatieModel,IEnumerable<ReservatieModel>>(monitorbeurtmodel, res,reservatie);
     return View(tuple);
 }
예제 #2
0
        public async Task<ActionResult> ReservatieToevoegen(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            
            var currentUser =  await manager.FindByIdAsync(User.Identity.GetUserId()); 
            var Monitorbeurt = db.MonitorBeurt.Single(monitor => monitor.MonitorBeurtId == id);
            
            foreach(ReservatieModel rest in db.Reservatie)
            {
               if(rest.ToezichtbeurtId == (int)id && rest.UserName == currentUser.UserName) 
               {
                   return RedirectToAction("index");
               }
            }            
            
            ReservatieModel res = new ReservatieModel();
            res.ToezichtbeurtId = (int)id;
            
            res.UserName =  currentUser.UserName; 
            res.AangepastOp = System.DateTime.Now;
            res.AangemaaktOp = System.DateTime.Now;

            if (ModelState.IsValid)
            {
                if(Monitorbeurt.Gereserveerd < Monitorbeurt.Capaciteit)
                {
                    Monitorbeurt.Gereserveerd += 1;
                    db.Entry(Monitorbeurt).State = EntityState.Modified;
                    db.Reservatie.Add(res);
                    db.SaveChanges();
                }
                return RedirectToAction("Index");
            }

            ViewBag.ToezichtbeurtId = new SelectList(db.MonitorBeurt, "MonitorBeurtId", "Start", res.ToezichtbeurtId);
            
            return RedirectToAction("index");           
            
        }