コード例 #1
0
        private async void ExecuteScheduleRenovation()
        {
            RoomAlreadyInUse = InvalidTimeFrame = false;
            var renovationStartPeriod = RenovationStartDate + RenovationStartTime?.TimeOfDay;
            var renovationEndPeriod   = RenovationEndDate + RenovationEndTime?.TimeOfDay;

            if (renovationEndPeriod <= renovationStartPeriod || renovationStartPeriod == null || renovationEndPeriod == null)
            {
                InvalidTimeFrame = true;
                return;
            }

            // Trying to save some RAM
            if ((await _calendarEntryService.GetAllByRoomAndTimeFrame(CurrentlySelectedRoom.Room, renovationStartPeriod.Value, renovationEndPeriod.Value)).Count != 0)
            {
                RoomAlreadyInUse = true;
                return;
            }

            var addedItems = await AddedEquipmentItems();

            var removedItems = await RemovedEquipmentItems();

            var roomToJoinTo = RoomToJoinTo?.Room;

            await _renovationService.Create(CurrentlySelectedRoom.Room, roomToJoinTo, NewRoomType,
                                            renovationStartPeriod.Value, renovationEndPeriod.Value, SplittingRoom,
                                            removedItems, addedItems);

            if (removedItems.Count > 0)
            {
                foreach (var equipmentItem in removedItems)
                {
                    await _equipmentItemService.Create(equipmentItem.EquipmentType, 1);
                }
            }

            Calendar.AddEvents((await _calendarEntryService.GetAllByRoomAndTimeFrame(CurrentlySelectedRoom.Room, renovationStartPeriod.Value, renovationEndPeriod.Value)).ToList());
            RenovationEndDate = RenovationStartDate = RenovationStartTime = RenovationEndTime = null;
            SplittingRoom     = false;
            OtherRenovations  = false;
            AddedEquipmentTypes.Clear();
            RemovedEquipmentTypes.Clear();
            LoadFreeEquipmentTypes();
            LoadRoomEquipmentTypes();
        }