Exemple #1
0
        private string CreateFurniture(OperationModel model)
        {
            var furnitureId = _furnitureRepository.Create(model.FurnitureType);
            var roomId = GetRoomId(model.RoomName);

            if (_historyRepository.RoomAliveInPast(roomId, model.Date))
                _historyRepository.AddOperation((int)HistoryOperationNameEnum.DeltaFurniture, roomId, model.Date, 1, furnitureId);
            else
                throw new InvalidOperationException();
            return string.Empty;
        }
Exemple #2
0
        private string RemoveRoom(OperationModel model)
        {
            var roomId = GetRoomId(model.RoomName);
            var transferRoomId = GetRoomId(model.Transfer);
            var roomState = GetRoomState(roomId, model.Date);

            if (_rules.CanDeleteRoom(roomState, roomId, transferRoomId, model.Date))
            {
                RemoveFurniture(roomState.Furniture, roomId, model.Date);
                _historyRepository.AddOperation((int)HistoryOperationNameEnum.DeltaRoooms, roomId, model.Date, -1);
                AddFurniture(roomState.Furniture, transferRoomId, model.Date);
            }

            return string.Empty;
        }
Exemple #3
0
        private string CreateRoom(OperationModel model)
        {
            var id = _roomRepository.GetIdByName(model.RoomName);

            if (_rules.ValidateCreateRoom(id, model.Date))
            {
                _historyRepository.AddOperation((int)HistoryOperationNameEnum.DeltaRoooms, id.Value, model.Date, 1);
                return model.RoomName;
            }
            
            if (!id.HasValue)
            {
                id = _roomRepository.Create(model.RoomName);
                _historyRepository.AddOperation((int)HistoryOperationNameEnum.DeltaRoooms, id.Value, model.Date, 1);
                return model.RoomName;
            }
            
            throw new InvalidOperationException();
        }
Exemple #4
0
        private string MoveFurniture(OperationModel model)
        {
            var furnitureId = GetFurnitureId(model.FurnitureType);
            var toRoomId = GetRoomId(model.ToRoom);
            var fromRoomId = GetRoomId(model.FromRoom);

            if (_rules.CanMoveFurniture(toRoomId, fromRoomId, furnitureId, model.Date))
            {
                _historyRepository.AddOperation((int)HistoryOperationNameEnum.DeltaFurniture, fromRoomId, model.Date, -1, furnitureId);
                _historyRepository.AddOperation((int)HistoryOperationNameEnum.DeltaFurniture, toRoomId, model.Date, 1, furnitureId);
            }
            
            return string.Empty;
        }
Exemple #5
0
        private string History(OperationModel model)
        {
            var message = new StringBuilder();
            if (string.IsNullOrEmpty(model.Short))
            {
                var firstDate = _historyRepository.GetFirstDate();
                if (!firstDate.HasValue)
                    throw new InvalidOperationException();

                var lastDate = _historyRepository.GetLastDate();
                do
                {
                    var roomsStates = _historyRepository.GetRoomsStates(firstDate.Value);
                    foreach (var roomState in roomsStates)
                    {
                        foreach (var furniture in roomState.Furniture)
                        {
                            message.Append(string.Format("Название комнаты: {0}, тип мебели: {1}, количество: {2}, дата: {3} \n",
                                roomState.RoomName, furniture.Name, furniture.Count, firstDate.Value.ToShortDateString()));
                        }
                    }
                    firstDate = firstDate.Value.AddDays(1);
                } while (firstDate <= lastDate);
                
            }
            else
            {
                var dates = _historyRepository.GetAllDates();
                if (!dates.Any())
                    throw new InvalidOperationException();

                foreach (var date in dates)
                {
                    message.Append(date.ToShortDateString() + " \n");
                }
            }
            return message.ToString();
        }
Exemple #6
0
 private string Query(OperationModel model)
 {
     var date = model.HistoryDate.HasValue ? model.HistoryDate.Value : DateTime.Now;
     var message = new StringBuilder();
     var roomsStates = _historyRepository.GetRoomsStates(date);
     foreach (var roomState in roomsStates)
     {
             foreach (var furniture in roomState.Furniture)
             {
                 message.Append(string.Format("Название комнаты: {0}, тип мебели: {1}, количество: {2} \n",
                     roomState.RoomName, furniture.Name, furniture.Count));
             }
     }
     return message.ToString();
 }