Ejemplo n.º 1
0
        public async Task <IActionResult> GetCompanyProfile()
        {
            List <AvioCompanyProfileDTO> avioCompanyProfileDTOList = new List <AvioCompanyProfileDTO>();

            if (ModelState.IsValid)
            {
                List <AvioCompany> companies = await AvioService.GetCompanies();

                List <AvioCompanyProfile> companiesProfile  = new List <AvioCompanyProfile>();
                List <double>             avioCompanyRating = new List <double>();
                List <int> avioCompanyRatingPicture         = new List <int>();

                foreach (var avioCompany in companies)
                {
                    companiesProfile.Add(await AvioService.GetCompanyProfile(avioCompany.AvioCompanyId));
                    avioCompanyRating.Add(await AvioService.GetAverageCompanyRating(avioCompany.AvioCompanyId));
                    avioCompanyRatingPicture.Add((int)(Math.Round(await AvioService.GetAverageCompanyRating(avioCompany.AvioCompanyId))));
                }

                for (int i = 0; i < companies.Count; i++)
                {
                    string allDestinations = "";
                    for (int j = 0; j < companies[i].Destinations.Count; j++)
                    {
                        if (j < companies[i].Destinations.Count - 1)
                        {
                            allDestinations += companies[i].Destinations[j].Name + ", ";
                        }
                        else
                        {
                            allDestinations += companies[i].Destinations[j].Name;
                        }
                    }

                    AvioCompanyProfileDTO acpDTO = new AvioCompanyProfileDTO()
                    {
                        Id            = companies[i].AvioCompanyId,
                        Name          = companiesProfile[i].Name,
                        Destinations  = allDestinations,
                        Address       = companiesProfile[i].Address,
                        Description   = companiesProfile[i].PromoDescription,
                        Rating        = avioCompanyRating[i],
                        RatingPicture = avioCompanyRatingPicture[i]
                    };
                    avioCompanyProfileDTOList.Add(acpDTO);
                }

                return(Ok(new { avioCompanyProfileDTOList }));
            }

            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetAvioCompanies()
        {
            var avioCompanies = await AvioService.GetCompanies();

            List <AvioCompanyDTO> retVal = new List <AvioCompanyDTO>();

            foreach (AvioCompany avioCompany in avioCompanies)
            {
                var avioCompanyProfile = await AvioService.GetCompanyProfile(avioCompany.AvioCompanyProfileId);

                retVal.Add(new AvioCompanyDTO()
                {
                    Id          = avioCompany.AvioCompanyId,
                    Name        = avioCompanyProfile.Name,
                    Address     = avioCompanyProfile.Address,
                    Description = avioCompanyProfile.PromoDescription
                });
            }

            return(Ok(retVal));
        }