Exemplo n.º 1
0
        public JsonResult GetCommunities([FromQuery] QueryParamsHelper queryParameters)
        {
            JSONObjectResult result = new JSONObjectResult
            {
                Status = System.Net.HttpStatusCode.OK
            };

            try
            {
                var data   = _communityService.GetCommunities(queryParameters, out long totalCount);
                var mapped = _mapper.Map <List <CommunityViewModel> >(data);

                var pagination = new
                {
                    totalCount,
                    pageSize    = queryParameters.PageCount,
                    currentPage = queryParameters.Page,
                    totalPages  = queryParameters.GetTotalPages(totalCount)
                };

                result.Data = new
                {
                    communities = mapped,
                    pagination
                };
            }
            catch (Exception e)
            {
                result.Status = System.Net.HttpStatusCode.BadRequest;
                result.Errors.Add(e.Message);
            }

            return(new JsonResult(result));
        }
Exemplo n.º 2
0
        public CommunitiesViewModel(
            ICommunityService communityService,
            IDialogService dialogService,
            INavigationService navigationService)
        {
            _communityService  = communityService;
            _dialogService     = dialogService;
            _navigationService = navigationService;

            AddCommunityCommand        = CreateCommand(AddCommunity);
            OpenCommunityDetailCommand = CreateCommand <Community>(OpenCommunityOverview);

            Communities = _communityService.GetCommunities();
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> GetCommunities(string ids = null, string email = null, string name = null, int page = 1, int pageSize = 50)
        {
            var criteria = new CommunityCriteriaModel
            {
                Ids      = ids?.SafeSplit(),
                Email    = email,
                Name     = name,
                Page     = page,
                PageSize = pageSize
            };

            var validationResults = _criteriaValidator.Validate(criteria);

            if (validationResults.IsValid)
            {
                return(Ok(await _communityService.GetCommunities(criteria).ConfigureAwait(false)));
            }
            validationResults.AddToModelState(ModelState, null);
            return(BadRequest(ModelState));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> GetAll()
        {
            var communities = await _communityService.GetCommunities();

            return(Ok(_mapper.Map <IEnumerable <CommunityDto> >(communities)));
        }