Ejemplo n.º 1
0
        public ChangeActivityOutput <GameTaskDto, long> ChangeActivity(ChangeActivityInput input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            GameTask gameTaskEntity = GameTaskRepository.Get(input.EntityId);

            if (gameTaskEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"GameTask\"");
            }

            if (!GameTaskPolicy.CanChangeActivityForEntity(gameTaskEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionChangeActivityDenied, "\"GameTask\"");
            }

            gameTaskEntity.IsActive = input.IsActive == null ? !gameTaskEntity.IsActive : (bool)input.IsActive;

            GameTaskDto newGameTaskDto = (gameTaskEntity).MapTo <GameTaskDto>();

            GameTaskRepository.Update(gameTaskEntity);

            GameTaskRepository.Includes.Clear();

            return(new ChangeActivityOutput <GameTaskDto, long>()
            {
                Entity = newGameTaskDto
            });
        }
Ejemplo n.º 2
0
        public RetrieveAllPagedResultOutput <GameTaskDto, long> RetrieveAllPagedResult(RetrieveAllGameTasksPagedResultInput input)
        {
            if (input.IsActive ?? true)
            {
                UowManager.Current.EnableFilter(Filters.IPassivableFilter);
            }

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            IQueryable <GameTask> gameTasksQuery = GameTaskPolicy.CanRetrieveManyEntities(
                GameTaskRepository.GetAll()
                .WhereIf(!input.GameTaskIds.IsNullOrEmpty(), r => input.GameTaskIds.Contains(r.Id))
                .WhereIf(!String.IsNullOrEmpty(input.Name), r => r.Name.ToLower().Contains(input.Name.ToLower())));

            int totalCount = gameTasksQuery.Count();
            IReadOnlyList <GameTaskDto> gameTaskDtos = gameTasksQuery
                                                       .OrderBy(r => r.Order).ThenByDescending(r => r.IsActive).ThenBy(r => r.Name)
                                                       .Skip(input.SkipCount).Take(input.MaxResultCount)
                                                       .ToList().MapIList <GameTask, GameTaskDto>().ToList();

            GameTaskRepository.Includes.Clear();

            return(new RetrieveAllPagedResultOutput <GameTaskDto, long>()
            {
                Items = gameTaskDtos,
                TotalCount = totalCount
            });
        }
Ejemplo n.º 3
0
        public UpdateOutput <GameTaskDto, long> Update(UpdateInput <GameTaskDto, long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            GameTask newGameTaskEntity = input.Entity.MapTo <GameTask>();

            if (newGameTaskEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"GameTask\"");
            }

            if (!GameTaskPolicy.CanUpdateEntity(newGameTaskEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"GameTask\"");
            }

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            GameTaskRepository.Update(newGameTaskEntity);
            GameTaskDto newGameTaskDto = (GameTaskRepository.Get(newGameTaskEntity.Id)).MapTo <GameTaskDto>();

            GameTaskRepository.Includes.Clear();

            return(new UpdateOutput <GameTaskDto, long>()
            {
                UpdatedEntity = newGameTaskDto
            });
        }
Ejemplo n.º 4
0
        public CreateOutput <GameTaskDto, long> Create(CreateInput <GameTaskDto, long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            GameTask newGameTaskEntity = input.Entity.MapTo <GameTask>();

            newGameTaskEntity.IsActive = true;

            if (!GameTaskPolicy.CanCreateEntity(newGameTaskEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"GameTask\"");
            }

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            GameTaskDto newGameTaskDto = (GameTaskRepository.Insert(newGameTaskEntity)).MapTo <GameTaskDto>();

            GameTaskRepository.Includes.Clear();

            return(new CreateOutput <GameTaskDto, long>()
            {
                CreatedEntity = newGameTaskDto
            });
        }
Ejemplo n.º 5
0
        public RetrieveAllOutput <GameTaskDto, long> RetrieveAll(RetrieveAllGameTaskInput input)
        {
            if (input.IsActive ?? true)
            {
                UowManager.Current.EnableFilter(Filters.IPassivableFilter);
            }

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            IList <GameTask> gameTaskEntities = GameTaskPolicy.CanRetrieveManyEntities(
                GameTaskRepository.GetAll()
                .WhereIf(!input.GameTaskIds.IsNullOrEmpty(), r => input.GameTaskIds.Contains(r.Id))
                .WhereIf(!String.IsNullOrEmpty(input.Name), r => r.Name.ToLower().Contains(input.Name.ToLower())))
                                                .ToList();

            IList <GameTaskDto> result = gameTaskEntities.MapIList <GameTask, GameTaskDto>();

            GameTaskRepository.Includes.Clear();

            return(new RetrieveAllOutput <GameTaskDto, long>()
            {
                RetrievedEntities = result
            });
        }
Ejemplo n.º 6
0
        private GameTask UpdateGameTaskEntity(GameTask existGameTask, GameTaskDto newGameTask)
        {
            existGameTask.Description    = newGameTask.Description;
            existGameTask.GameTaskTypeId = newGameTask.GameTaskTypeId;
            existGameTask.IsActive       = newGameTask.IsActive;
            existGameTask.Name           = newGameTask.Name;
            existGameTask.Order          = newGameTask.Order;
            existGameTask.TaskText       = newGameTask.TaskText;

            UpdateGameTaskEntityRelations(existGameTask, newGameTask);

            return(GameTaskRepository.Update(existGameTask));
        }
Ejemplo n.º 7
0
        public RetrieveAllGameTasksLikeComboBoxesOutput RetrieveAllGameTasksLikeComboBoxes(RetrieveAllGameTasksLikeComboBoxesInput input)
        {
            if (input.IsActive ?? true)
            {
                UowManager.Current.EnableFilter(Filters.IPassivableFilter);
            }

            IReadOnlyList <ComboboxItemDto> gameTasksLikeComboBoxes = GameTaskPolicy.CanRetrieveManyEntities(
                GameTaskRepository.GetAll()).ToList()
                                                                      .Select(r => new ComboboxItemDto(r.Id.ToString(), r.Name)).ToList();

            return(new RetrieveAllGameTasksLikeComboBoxesOutput()
            {
                Items = gameTasksLikeComboBoxes
            });
        }
Ejemplo n.º 8
0
        private void UpdateGameEntityRelations(Game existGameEntity, GameDto newGameEntity)
        {
            IList <GameTask> gameTasksForDelete = existGameEntity.GameTasks.ToList();

            foreach (GameTaskDto newGameTask in newGameEntity.GameTasks)
            {
                if (newGameTask.Id > 0)
                {
                    GameTask existGameTask = existGameEntity.GameTasks.First(r => r.Id == newGameTask.Id);
                    gameTasksForDelete.Remove(existGameTask);
                    UpdateGameTaskEntity(existGameTask, newGameTask);
                }
                else
                {
                    GameTaskRepository.Insert(newGameTask.MapTo <GameTask>());
                }
            }

            GameTaskRepository.RemoveRange(gameTasksForDelete);
        }
Ejemplo n.º 9
0
        public RetrieveTipsForGameTaskOutput RetrieveTipsForGameTask(RetrieveTipsForGameTaskInput input)
        {
            if (!(input.GameTaskId > 0))
            {
                return new RetrieveTipsForGameTaskOutput()
                       {
                           Tips = new List <TipDto>()
                       }
            }
            ;

            GameTaskRepository.Includes.Add(r => r.Game);
            GameTaskRepository.Includes.Add(r => r.Tips);

            GameTask gameTaskEntity = GameTaskRepository.Get(input.GameTaskId);
            Game     gameEntity     = gameTaskEntity.Game;

            if (gameEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"Game\"");
            }

            if (!GamePolicy.CanRetrieveEntity(gameEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionRetrieveDenied, "\"Game\"");
            }

            IList <Tip>    tipEntities     = gameTaskEntity.Tips.ToList();
            IList <TipDto> tipsForGameTask = tipEntities.MapIList <Tip, TipDto>();

            GameTaskRepository.Includes.Clear();

            return(new RetrieveTipsForGameTaskOutput()
            {
                Tips = tipsForGameTask
            });
        }
    }
Ejemplo n.º 10
0
        public DeleteOutput <long> Delete(DeleteInput <long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            GameTask gameTaskEntityForDelete = GameTaskRepository.Get(input.EntityId);

            if (gameTaskEntityForDelete == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"GameTask\"");
            }

            if (!GameTaskPolicy.CanDeleteEntity(gameTaskEntityForDelete))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionDeleteDenied, "\"GameTask\"");
            }

            GameTaskRepository.Delete(gameTaskEntityForDelete);

            return(new DeleteOutput <long>()
            {
                DeletedEntityId = input.EntityId
            });
        }
Ejemplo n.º 11
0
        public RetrieveOutput <GameTaskDto, long> Retrieve(RetrieveGameTaskInput input)
        {
            if (input.IsActive ?? true)
            {
                UowManager.Current.EnableFilter(Filters.IPassivableFilter);
            }

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            IList <GameTask> gameTaskEntities = GameTaskRepository.GetAll()
                                                .WhereIf(input.Id != null, r => r.Id == input.Id)
                                                .WhereIf(!String.IsNullOrEmpty(input.Name), r => r.Name.ToLower().Contains(input.Name.ToLower()))
                                                .ToList();

            if (gameTaskEntities.Count != 1)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"GameTask\"");
            }

            if (!GameTaskPolicy.CanRetrieveEntity(gameTaskEntities.Single()))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionRetrieveDenied, "\"GameTask\"");
            }

            GameTaskDto gameTaskEntity = gameTaskEntities.Single().MapTo <GameTaskDto>();

            GameTaskRepository.Includes.Clear();

            return(new RetrieveOutput <GameTaskDto, long>()
            {
                RetrievedEntity = gameTaskEntity
            });
        }