Exemplo n.º 1
0
        public async Task <UpdateRoomResponse> UpdateRoom(UpdateRoomRequest requestModel)
        {
            //Find and check if room exists in database
            var room = await FindById(requestModel.RoomId);

            //Check if room type exists
            if (!await _param.IsOfParamType(requestModel.RoomType, GlobalParams.ParamTypeRoomType))
            {
                throw new HttpStatusCodeException(HttpStatusCode.NotFound, "RoomService: RoomType is not valid");
            }

            //Update room with new information
            room = UpdateRoomRequest.UpdateToRoom(room, requestModel);


            //Update to database
            room = await _repoWrapper.Room.UpdateAsync(room, room.RoomId);

            var equipments =
                (List <Equipment>) await _repoWrapper.Equipment.FindAllAsyncWithCondition(e => e.RoomId == room.RoomId);

            List <int> equipmentIds = null;

            if (EnumerableExtensions.Any(equipments))
            {
                equipmentIds = equipments.Select(e => e.EquipmentId).ToList();
            }

            return(UpdateRoomResponse.ResponseFromRoom(room, equipmentIds));
        }
        //Used to check request for Send and edit room booking
        private async Task <HttpCodeReturn> Check_PriorityType_Month_TargetRoomType(int priorityType, int month, int targetRoomType)
        {
            //Check if PriorityType is valid
            if (!await _paramService.IsOfParamType(priorityType, GlobalParams.ParamTypeStudentPriorityType))
            {
                return(new HttpCodeReturn(HttpStatusCode.BadRequest, "RoomBookingService: PriorityType is Invalid"));
            }

            //Check if Month is valid
            if (month <= 0)
            {
                return(new HttpCodeReturn(HttpStatusCode.BadRequest, "RoomBookingService: Month is invalid"));
            }

            //Check if TargetRoomType is valid
            if (!await _paramService.IsOfParamType(targetRoomType, GlobalParams.ParamTypeRoomType))
            {
                return(new HttpCodeReturn(HttpStatusCode.BadRequest, "RoomBookingService: RoomType is invalid"));
            }

            //return ok
            return(new HttpCodeReturn(HttpStatusCode.OK));
        }