public async Task <IActionResult> GetCompanyDetails(long id)
        {
            AvioCompanyProfileDTO avioCompanyProfileDTO = new AvioCompanyProfileDTO();

            if (ModelState.IsValid)
            {
                AvioCompany company = await AvioService.GetCompany(id);

                AvioCompanyProfile companyProfile  = new AvioCompanyProfile();
                int avioCompanyRatingPicture       = 0;
                List <Destination> destinationList = company.Destinations;

                string allDestinations = "";
                for (int i = 0; i < destinationList.Count; i++)
                {
                    allDestinations += destinationList[i].Name + ",";
                }

                companyProfile = await AvioService.GetCompanyProfile(id);

                avioCompanyRatingPicture = (int)(Math.Round(await AvioService.GetAverageCompanyRating(id)));

                avioCompanyProfileDTO.Id              = company.AvioCompanyId;
                avioCompanyProfileDTO.Name            = companyProfile.Name;
                avioCompanyProfileDTO.RatingPicture   = avioCompanyRatingPicture;
                avioCompanyProfileDTO.Address         = companyProfile.Address;
                avioCompanyProfileDTO.Description     = companyProfile.PromoDescription;
                avioCompanyProfileDTO.Destinations    = allDestinations;
                avioCompanyProfileDTO.DestinationList = destinationList;

                return(Ok(new { avioCompanyProfileDTO }));
            }
            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Ejemplo n.º 2
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));
        }