示例#1
0
        public JsonResult GetAll()
        {
            var response = new JsonResultBody();

            response.Status = System.Net.HttpStatusCode.OK;

            try
            {
                var data = _repository.GetAll();
                response.Data = Mapper.Map <IEnumerable <Country>, IEnumerable <CountryViewModel> >(data);
            }
            catch (DbEntityValidationException ex)
            {
                response.Status = System.Net.HttpStatusCode.InternalServerError;

                foreach (DbEntityValidationResult result in ex.EntityValidationErrors)
                {
                    response.Errors = (from ve in result.ValidationErrors select ve.ErrorMessage).ToList();
                }
            }
            catch (Exception ex)
            {
                response.Status = System.Net.HttpStatusCode.InternalServerError;
                response.Errors.Add(ex.Message);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public RetrieveAllPagedResultOutput <ConditionDto, long> RetrieveAllPagedResult(
            RetrieveAllConditionsPagedResultInput input)
        {
            ConditionRepository.Includes.Add(r => r.LastModifierUser);
            ConditionRepository.Includes.Add(r => r.CreatorUser);
            ConditionRepository.Includes.Add(r => r.ConditionType);

            IQueryable <Condition> conditionsQuery = ConditionPolicy.CanRetrieveManyEntities(
                ConditionRepository.GetAll()
                .WhereIf(!input.ConditionIds.IsNullOrEmpty(), r => input.ConditionIds.Contains(r.Id))
                .WhereIf(!String.IsNullOrEmpty(input.Name), r => r.Name.ToLower().Contains(input.Name.ToLower())))
                                                     .OrderBy(r => r.Order);

            int totalCount = conditionsQuery.Count();
            IReadOnlyList <ConditionDto> conditionDtos = conditionsQuery
                                                         .OrderBy(r => r.Name)
                                                         .Skip(input.SkipCount).Take(input.MaxResultCount)
                                                         .ToList().MapIList <Condition, ConditionDto>().ToList();

            ConditionRepository.Includes.Clear();

            return(new RetrieveAllPagedResultOutput <ConditionDto, long>()
            {
                Items = conditionDtos,
                TotalCount = totalCount
            });
        }
示例#3
0
        public RetrieveOutput <ConditionDto, long> Retrieve(RetrieveConditionInput input)
        {
            ConditionRepository.Includes.Add(r => r.LastModifierUser);
            ConditionRepository.Includes.Add(r => r.CreatorUser);
            ConditionRepository.Includes.Add(r => r.ConditionType);

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

            if (!ConditionPolicy.CanRetrieveEntity(conditionEntities.Single()))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionRetrieveDenied, "\"Condition\"");
            }

            ConditionDto conditionEntity = conditionEntities.Single().MapTo <ConditionDto>();

            ConditionRepository.Includes.Clear();

            return(new RetrieveOutput <ConditionDto, long>()
            {
                RetrievedEntity = conditionEntity
            });
        }
示例#4
0
        public RetrieveAllConditionsLikeComboBoxesOutput RetrieveAllConditionsLikeComboBoxes(
            RetrieveAllConditionsLikeComboBoxesInput input)
        {
            IReadOnlyList <ComboboxItemDto> conditionsLikeComboBoxes = ConditionPolicy.CanRetrieveManyEntities(
                ConditionRepository.GetAll()).ToList().OrderBy(r => r.Order)
                                                                       .Select(r => new ComboboxItemDto(r.Id.ToString(), r.Name)).ToList();

            return(new RetrieveAllConditionsLikeComboBoxesOutput()
            {
                Items = conditionsLikeComboBoxes
            });
        }
示例#5
0
        public RetrieveAllOutput <ConditionDto, long> RetrieveAll(RetrieveAllConditionInput input)
        {
            ConditionRepository.Includes.Add(r => r.LastModifierUser);
            ConditionRepository.Includes.Add(r => r.CreatorUser);
            ConditionRepository.Includes.Add(r => r.ConditionType);

            IList <Condition> conditionEntities = ConditionPolicy.CanRetrieveManyEntities(
                ConditionRepository.GetAll()
                .WhereIf(!input.ConditionIds.IsNullOrEmpty(), r => input.ConditionIds.Contains(r.Id))
                .WhereIf(!String.IsNullOrEmpty(input.Name), r => r.Name.ToLower().Contains(input.Name.ToLower())))
                                                  .OrderBy(r => r.Order)
                                                  .ToList();

            IList <ConditionDto> result = conditionEntities.MapIList <Condition, ConditionDto>();

            ConditionRepository.Includes.Clear();

            return(new RetrieveAllOutput <ConditionDto, long>()
            {
                RetrievedEntities = result
            });
        }
示例#6
0
        //
        // GET: /ConditionTemplate/

        public ActionResult Index()
        {
            IRepository <Models.Condition> repo = new ConditionRepository();

            return(View(repo.GetAll()));
        }