Example #1
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
            });
        }
Example #2
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
            });
        }
Example #3
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
            });
        }
Example #4
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
            });
        }
Example #5
0
 // GET api/Tips
 public IEnumerable <Tip> Get()
 {
     return(context.GetAll());
 }