Ejemplo n.º 1
0
        public ActionResult List()
        {
            var model = new RoomsListViewModel
            {
                Rooms = Context.Rooms.ToList(),
                DepartmentsNames = Context.Departments.Select(x => x.Name).ToList()
            };

            Session["Rooms"] = model.Rooms;
            Session["DepartmentsNames"] = model.DepartmentsNames;

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Create(RoomsListViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Rooms = (Session["Rooms"] as IList<Room>) ?? new List<Room>();
                model.DepartmentsNames = (Session["DepartmentsNames"] as IList<string>) ?? new List<string>();

                return View("List", model);
            }

            var roomService = new RoomService(Context);

            roomService.AssignRoomToDepartment(model.NewRoomDepartment, model.NewRoomName);

            return RedirectToAction("List");
        }