public ActionResult Create(RoomLookupModel model)
        {
            IEnumerable<SelectListItem> selectList = from b in db.Buildings
                                                     select new SelectListItem
                                                     {
                                                         Value = b.BuildingCode,
                                                         Text = b.BuildingCode + " - " + b.Name

                                                     };
            ViewBag.EditDepartments = new SelectList(selectList, "Value", "Text");

            model.facilityEdit = (from f in db.Facilities select f).ToList();

            List<int> roomFac = (from i in db.RoomFacilities where i.RoomID == 0 select i.FacilityID).ToList();

            Room rooms = new Room();
            rooms = model.roomsCreate;

            if (ModelState.IsValid)
            {
                db.Entry(rooms).State = EntityState.Added;
                db.SaveChanges();

                List<int> fac = (from f in db.Facilities select f.FacilityID).ToList();

                int facsNo = fac.Last();
                for (int i = 1; i <= facsNo; i++)
                {

                    if (Request["fac-" + i] == "1")
                    {

                        RoomFacility newRF = new RoomFacility();
                        newRF.RoomID = rooms.RoomID;
                        newRF.FacilityID = i;
                        db.Entry(newRF).State = EntityState.Added;
                        db.SaveChanges();

                    }

                }

                return RedirectToAction("Index");

            }

            TempData["notice"] = "Password is incorrect. Please try again.";

            return View(model);
        }
        public ActionResult Edit(RoomLookupModel model)
        {
            Room rooms = new Room();
            rooms = model.roomsEdit;

            //  List<int> roomFac = (from i in db.RoomFacilities where i.RoomID == rooms.RoomID select i.FacilityID).ToList();

            //  model.checkedFacs = roomFac;

            IEnumerable<SelectListItem> selectList = from b in db.Buildings
                                                     select new SelectListItem
                                                     {
                                                         Value = b.BuildingCode,
                                                         Text = b.BuildingCode + " - " + b.Name

                                                     };

            ViewBag.EditDepartments = new SelectList(selectList, "Value", "Text");

            if (ModelState.IsValid)
            {
                if (rooms != null)
                {

                    db.Entry(rooms).State = EntityState.Modified;
                    db.SaveChanges();

                }

                List<RoomFacility> rFac = new List<RoomFacility>();
                rFac = (from r in db.RoomFacilities where r.RoomID == rooms.RoomID select r).ToList();

                foreach (RoomFacility r in rFac)
                {

                    db.Entry(r).State = EntityState.Deleted;
                    db.SaveChanges();

                }

                List<int> fac = (from f in db.Facilities select f.FacilityID).ToList();

                int facsNo = fac.Last();
                for (int i = 1; i <= facsNo; i++)
                {

                    if (Request["fac-" + i] == "1")
                    {

                        RoomFacility newRF = new RoomFacility();
                        newRF.RoomID = rooms.RoomID;
                        newRF.FacilityID = i;
                        db.Entry(newRF).State = EntityState.Added;
                        db.SaveChanges();

                    }

                }

                return RedirectToAction("Index");

            }

            return View(rooms);
        }