Exemplo n.º 1
0
        public async Task <IActionResult> Index([FromQuery] int?page = 1, [FromQuery] string?skill = null, [FromQuery] bool?filterMySkill = false)
        {
            (int totalCount, IEnumerable <JobOfferDto> offers)model;
            if (User.IsInRole("Company"))
            {
                var user = await userFacade.GetByIdAsync(int.Parse(User.Identity.Name));

                var offers = await jobOfferFacade.GetByCompanyIdAsync(user.CompanyId.Value);

                if (offers == null)
                {
                    model = (0, new List <JobOfferDto>());
                }
                else
                {
                    model = (offers.Count(), offers);
                }
            }
            else if (User.IsInRole("JobSeeker") && filterMySkill.HasValue && filterMySkill.Value)
            {
                var user = await userFacade.GetByIdAsync(int.Parse(User.Identity.Name));

                var skillTags = (await jobSeekerFacade.GetByIdAsync(user.JobSeekerId.Value)).Skills;
                model = await jobOfferFacade.GetAllAsync(PageSize, page ?? 1, skillTags);
            }
            else
            {
                model = await jobOfferFacade.GetAllAsync(PageSize, page ?? 1, skill == null?null : new List <string> {
                    skill
                });
            }

            var pagedModel = new PagedListViewModel <JobOfferDto>(
                new PaginationViewModel(page ?? 1, model.totalCount, PageSize), model.offers);

            return(View(pagedModel));
        }