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

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

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

                        db.SaveChanges();
                        return RedirectToAction("Index");

                    }

                    catch (DbEntityValidationException dbEx)
                    {
                        return RedirectToAction("Edit");
                    }

                }

            }
            return View(rooms);
        }
        public ActionResult AddBuilding(Building buildings)
        {
            Room rooms = new Room();
            if (ModelState.IsValid)
            {

                //db.Entry(buildings).State = EntityState.Added;
                //db.SaveChanges();
                //return View("Index");
            }

            return View("Edit");
        }
        //---------------------------------------------------------------------------------CREATE---------------
        //
        // GET: /Movies/Create
        public ActionResult Create()
        {
            RoomLookupModel model = new RoomLookupModel();
            Room rooms = new Room();
            model.roomsCreate = rooms;

            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");

            //copied from edit page for checkboxes

            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();
            //copied from edit page for checkboxes

            return View(model);
        }
        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);
        }
        public ActionResult Delete(RoomLookupModel model)
        {
            Room room = new Room();
            room = model.roomsDelete;

            if (ModelState.IsValid)
            {

                db.Entry(model.roomsDelete).State = EntityState.Deleted;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View("Delete");
        }