Exemple #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
            });
        }
Exemple #2
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
            });
        }
Exemple #3
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
            });
        }
Exemple #4
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));
        }
Exemple #5
0
        private void UpdateGameTaskEntityRelations(GameTask existGameTask, GameTaskDto newGameTask)
        {
            #region Updating Conditions

            IList <Condition> conditionsForDelete = existGameTask.Conditions.ToList();

            foreach (ConditionDto newCondition in newGameTask.Conditions)
            {
                if (newCondition.Id > 0)
                {
                    Condition existCondition = existGameTask.Conditions.First(r => r.Id == newCondition.Id);
                    conditionsForDelete.Remove(existCondition);
                    UpdateConditionEntity(existCondition, newCondition);
                }
                else
                {
                    ConditionRepository.Insert(newCondition.MapTo <Condition>());
                }
            }

            ConditionRepository.RemoveRange(conditionsForDelete);

            #endregion

            #region Updating Tips

            IList <Tip> tipsForDelete = existGameTask.Tips.ToList();

            foreach (TipDto newTip in newGameTask.Tips)
            {
                if (newTip.Id > 0)
                {
                    Tip existTip = existGameTask.Tips.First(r => r.Id == newTip.Id);
                    tipsForDelete.Remove(existTip);
                    UpdateTipEntity(existTip, newTip);
                }
                else
                {
                    TipRepository.Insert(newTip.MapTo <Tip>());
                }
            }

            TipRepository.RemoveRange(tipsForDelete);

            #endregion
        }
Exemple #6
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
            });
        }