示例#1
0
        public void AssignRoom(Department department, Room room)
        {
            if (department == null) throw new ArgumentNullException("department");
            if (room == null) throw new ArgumentNullException("room");

            var existingDepartment = Context.Departments.FirstOrDefault(x => x.Id == department.Id);
            if (existingDepartment == null)
            {
                throw new InvalidOperationException(string.Format("Department with id {0} does not exist", department.Id));
            }

            if (room.Id == Guid.Empty)
            {
                room.Id = Guid.NewGuid();
            }

            if (existingDepartment.Rooms.Any(x => x.Name == room.Name))
            {
                throw new InvalidOperationException(string.Format("Room {0} is already assigned to department {1}", room.Name, existingDepartment.Name));
            }

            room.Locations = Context.Locations.ToList();

            existingDepartment.Rooms.Add(room);
            Context.SaveChanges();
        }
示例#2
0
        public void AssignRoomToDepartment(Department department, Room room)
        {
            if (department == null) throw new ArgumentNullException("department");
            if (room == null) throw new ArgumentNullException("room");

            var departmentService = new DepartmentService(Context);
            departmentService.AssignRoom(department, room);
        }
示例#3
0
        public void AssignRoom(string departmentName, Room room)
        {
            if (string.IsNullOrEmpty(departmentName)) throw new ArgumentNullException("department");
            if (room == null) throw new ArgumentNullException("room");

            var department = Context.Departments.FirstOrDefault(x => x.Name == departmentName);

            AssignRoom(department, room);
        }
示例#4
0
        public void AssignRoomToDepartment(string departmentName, Room room)
        {
            if (string.IsNullOrEmpty(departmentName)) throw new ArgumentNullException("department");
            if (room == null) throw new ArgumentNullException("room");

            var departmentService = new DepartmentService(Context);

            departmentService.AssignRoom(departmentName, room);
        }
示例#5
0
        public void Delete(Room room)
        {
            if (room == null) throw new ArgumentNullException("room");

            if (Context.Entry(room).State == EntityState.Detached)
            {
                room = Context.Rooms.FirstOrDefault(x => x.Id == room.Id);
            }

            Context.Rooms.Remove(room);
            Context.SaveChanges();
        }
示例#6
0
        public void AssignDevice(Room room, Device device)
        {
            if (room == null) throw new ArgumentNullException("room");
            if (device == null) throw new ArgumentNullException("device");

            var existingRoom = Context.Rooms.FirstOrDefault(x => x.Id == room.Id);
            if (existingRoom == null)
            {
                throw new InvalidOperationException(string.Format("Room with id {0} does not exist", room.Id));
            }

            if (device.Location == null)
            {
                throw new ArgumentException("Device is not assigned to a location");
            }

            if (!existingRoom.Locations.Any(x => x.Name == device.Location.Name))
            {
                throw new InvalidOperationException(string.Format("Location {0} is not available in room {1}", device.Location.Name, room.Name));
            }

            existingRoom.Devices.Add(device);
            Context.SaveChanges();
        }