Esempio n. 1
0
        public RetrieveAllPagedResultOutput <TipDto, long> RetrieveAllPagedResult(RetrieveAllTipsPagedResultInput input)
        {
            TipRepository.Includes.Add(r => r.LastModifierUser);
            TipRepository.Includes.Add(r => r.CreatorUser);

            IQueryable <Tip> tipsQuery = TipPolicy.CanRetrieveManyEntities(
                TipRepository.GetAll()
                .WhereIf(!input.TipIds.IsNullOrEmpty(), r => input.TipIds.Contains(r.Id))
                .WhereIf(!String.IsNullOrEmpty(input.Name), r => r.Name.ToLower().Contains(input.Name.ToLower())))
                                         .OrderBy(r => r.Order);

            int totalCount = tipsQuery.Count();
            IReadOnlyList <TipDto> tipDtos = tipsQuery
                                             .OrderBy(r => r.Order).ThenBy(r => r.Name)
                                             .Skip(input.SkipCount).Take(input.MaxResultCount)
                                             .ToList().MapIList <Tip, TipDto>().ToList();

            TipRepository.Includes.Clear();

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

            Tip newTipEntity = input.Entity.MapTo <Tip>();

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

            if (!TipPolicy.CanUpdateEntity(newTipEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"Tip\"");
            }

            TipRepository.Includes.Add(r => r.LastModifierUser);
            TipRepository.Includes.Add(r => r.CreatorUser);

            TipRepository.Update(newTipEntity);
            TipDto newTipDto = (TipRepository.Get(newTipEntity.Id)).MapTo <TipDto>();

            TipRepository.Includes.Clear();

            return(new UpdateOutput <TipDto, long>()
            {
                UpdatedEntity = newTipDto
            });
        }
Esempio n. 3
0
        public RetrieveOutput <TipDto, long> Retrieve(RetrieveTipInput input)
        {
            TipRepository.Includes.Add(r => r.LastModifierUser);
            TipRepository.Includes.Add(r => r.CreatorUser);

            IList <Tip> tipEntities = TipRepository.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 (tipEntities.Count != 1)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"Tip\"");
            }

            if (!TipPolicy.CanRetrieveEntity(tipEntities.Single()))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionRetrieveDenied, "\"Tip\"");
            }

            TipDto tipEntity = tipEntities.Single().MapTo <TipDto>();

            TipRepository.Includes.Clear();

            return(new RetrieveOutput <TipDto, long>()
            {
                RetrievedEntity = tipEntity
            });
        }
Esempio n. 4
0
        private Tip UpdateTipEntity(Tip existTip, TipDto newTip)
        {
            existTip.TipText = newTip.TipText;
            existTip.Name    = newTip.Name;
            existTip.Order   = newTip.Order;

            return(TipRepository.Update(existTip));
        }
Esempio n. 5
0
        public RetrieveAllTipsLikeComboBoxesOutput RetrieveAllTipsLikeComboBoxes(RetrieveAllTipsLikeComboBoxesInput input)
        {
            IReadOnlyList <ComboboxItemDto> tipsLikeComboBoxes = TipPolicy.CanRetrieveManyEntities(
                TipRepository.GetAll()).ToList().OrderBy(r => r.Order)
                                                                 .Select(r => new ComboboxItemDto(r.Id.ToString(), r.Name)).ToList();

            return(new RetrieveAllTipsLikeComboBoxesOutput()
            {
                Items = tipsLikeComboBoxes
            });
        }
Esempio n. 6
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
        }
Esempio n. 7
0
        public RetrieveAllOutput <TipDto, long> RetrieveAll(RetrieveAllTipInput input)
        {
            TipRepository.Includes.Add(r => r.LastModifierUser);
            TipRepository.Includes.Add(r => r.CreatorUser);

            IList <Tip> tipEntities = TipPolicy.CanRetrieveManyEntities(
                TipRepository.GetAll()
                .WhereIf(!input.TipIds.IsNullOrEmpty(), r => input.TipIds.Contains(r.Id))
                .WhereIf(!String.IsNullOrEmpty(input.Name), r => r.Name.ToLower().Contains(input.Name.ToLower())))
                                      .OrderBy(r => r.Order)
                                      .ToList();

            IList <TipDto> result = tipEntities.MapIList <Tip, TipDto>();

            TipRepository.Includes.Clear();

            return(new RetrieveAllOutput <TipDto, long>()
            {
                RetrievedEntities = result
            });
        }
Esempio n. 8
0
        public DeleteOutput <long> Delete(DeleteInput <long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            Tip tipEntityForDelete = TipRepository.Get(input.EntityId);

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

            if (!TipPolicy.CanDeleteEntity(tipEntityForDelete))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionDeleteDenied, "\"Tip\"");
            }

            TipRepository.Delete(tipEntityForDelete);

            return(new DeleteOutput <long>()
            {
                DeletedEntityId = input.EntityId
            });
        }
Esempio n. 9
0
        public CreateOutput <TipDto, long> Create(CreateInput <TipDto, long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            Tip newTipEntity = input.Entity.MapTo <Tip>();

            if (!TipPolicy.CanCreateEntity(newTipEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"Tip\"");
            }

            TipRepository.Includes.Add(r => r.LastModifierUser);
            TipRepository.Includes.Add(r => r.CreatorUser);

            TipDto newTipDto = (TipRepository.Insert(newTipEntity)).MapTo <TipDto>();

            TipRepository.Includes.Clear();

            return(new CreateOutput <TipDto, long>()
            {
                CreatedEntity = newTipDto
            });
        }