Ejemplo n.º 1
0
        public async Task <PagedViewModelResult <PassInformationViewModel> > GetActivePasses(SearchParams searchParams)
        {
            _logger.LogInfo("Trying to get all active passes on language " + searchParams.Lang);
            try
            {
                PagedViewModelResult <PassInformationViewModel> passInformation = _mapper.Map <PaginatedList <PassInformation>, PagedViewModelResult <PassInformationViewModel> >(await _passRepository.GetActivePasses(_mapper.Map <PassInfoSearchParams>(searchParams)));

                //Get all passes which PTOs and pass descriptions are available
                var activePass = new List <PassInformationViewModel>();


                foreach (var item in passInformation.Items)
                {
                    //Filter based on language from the paginated result.
                    item.PassDescription = item?.PassDescription?.Where(p => p.SelectedLanguage == searchParams.Lang);

                    //Filter based on language from the list of active pass ptos mapper.
                    //Get all which PTOs are available
                    var activePTOs = new List <PassActivePTOViewModel>();
                    foreach (var element in item.PassActivePTOs)
                    {
                        element.PTOInformation.PTODescription = element?.PTOInformation?.PTODescription?.Where(p => p.SelectedLanguage == searchParams.Lang);
                        if (element.PTOInformation.PTODescription.Count() > 0)
                        {
                            activePTOs.Add(element);
                        }
                    }
                    item.PassActivePTOs = activePTOs;
                    if (item.PassActivePTOs.Count() > 0 && item.PassDescription.Count() > 0)
                    {
                        activePass.Add(item);
                    }
                }
                passInformation.Items = activePass;
                _logger.LogInfo("Retrieved all active passes on language " + searchParams.Lang);
                return(passInformation);
            }
            catch (Exception ex)
            {
                _logger.LogInfo(ex.Message);
                return(null);
            }
        }