public void AssignDeviceToRoom(Device device, string roomName) { if (device == null) throw new ArgumentNullException("device"); if (string.IsNullOrEmpty(roomName)) throw new ArgumentNullException("roomName"); var room = Context.Rooms.FirstOrDefault(x => x.Name == roomName); if (room == null) { throw new InvalidOperationException(string.Format("Room {0} was not found", roomName)); } var roomService = new RoomService(Context); roomService.AssignDevice(room, device); }
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"); }
public ActionResult Delete(Guid id) { var room = Context.Rooms.FirstOrDefault(x => x.Id == id); if (room == null) { return HttpNotFound(); } if (room.Devices.Any(x => x.IsLocalized)) { return HttpNotFound(); } var roomService = new RoomService(Context); roomService.Delete(room); return RedirectToAction("List"); }