Ejemplo n.º 1
0
        public async Task <IActionResult> RefreshBonusPoints()
        {
            var user = await _userService.GetCurrentUser();

            if (user != null)
            {
                var reservations = user.ReservedFlights;

                if (reservations != null)
                {
                    List <FlightHistoryDTO> flightsHistory = new List <FlightHistoryDTO>();

                    foreach (FlightReservation fr in reservations)
                    {
                        if (!fr.BonusTaken)
                        {
                            var flight = await _flightService.GetFlight(fr.FlightId);

                            if (flight != null)
                            {
                                if (DateTime.Now > (flight.Departure.AddHours(-3)))
                                {
                                    var company = await _avioService.GetCompany(flight.AvioCompanyId);

                                    if (company != null)
                                    {
                                        var companyProfile = await _avioService.GetCompanyProfile(company.AvioCompanyProfileId);

                                        if (companyProfile != null)
                                        {
                                            var sCoord = new GeoCoordinate(flight.DepartureLocation.Latitude, flight.DepartureLocation.Longitude);
                                            var eCoord = new GeoCoordinate(flight.ArrivalLocation.Latitude, flight.ArrivalLocation.Longitude);

                                            user.Bonus   += (int)(sCoord.GetDistanceTo(eCoord) / 100000);
                                            fr.BonusTaken = true;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    await _userService.UpdateUser(user);

                    return(Ok(200));
                }

                return(BadRequest("No reservations found!"));
            }

            return(BadRequest("User not found."));
        }
        public async Task <IActionResult> GetFlightsHistory()
        {
            var user = await _userService.GetCurrentUser();

            if (user != null)
            {
                var reservations = user.ReservedFlights;

                if (reservations != null)
                {
                    List <FlightHistoryDTO> flightsHistory = new List <FlightHistoryDTO>();

                    foreach (FlightReservation fr in reservations)
                    {
                        var flight = await _flightService.GetFlight(fr.FlightId);

                        if (flight != null)
                        {
                            if (DateTime.Now > (flight.Departure.AddHours(-3)))
                            {
                                var company = await _avioService.GetCompany(flight.AvioCompanyId);

                                if (company != null)
                                {
                                    var companyProfile = await _avioService.GetCompanyProfile(company.AvioCompanyProfileId);

                                    if (companyProfile != null)
                                    {
                                        flightsHistory.Add(new FlightHistoryDTO()
                                        {
                                            ReservationId     = fr.FlightReservationId,
                                            DepartureLocation = flight.DepartureLocation,
                                            ArrivalLocation   = flight.ArrivalLocation,
                                            Departure         = flight.Departure,
                                            AvioCompanyName   = companyProfile.Name
                                        });
                                    }
                                }
                            }
                        }
                    }

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

                return(BadRequest("No reservations found!"));
            }

            return(BadRequest("User not found."));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateCompanyProfile([FromBody] AvioCompanyProfile model)
        {
            if (ModelState.IsValid)
            {
                var user = await AvioAdminService.GetCurrentUser();

                if (user != null)
                {
                    var avioCompany = await AvioService.GetCompany(user.AvioCompanyId);

                    if (avioCompany != null)
                    {
                        var avioCompanyProfile = await AvioService.GetCompanyProfile(avioCompany.AvioCompanyProfileId);

                        avioCompanyProfile.Name             = model.Name;
                        avioCompanyProfile.Address          = model.Address;
                        avioCompanyProfile.PromoDescription = model.PromoDescription;

                        await AvioService.UpdateCompanyProfile(avioCompanyProfile);

                        return(Ok(200));
                    }

                    return(BadRequest("Avio company not found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            return(BadRequest("Not enough data provided."));
        }
        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.º 5
0
        public async Task <IActionResult> GetAdmins()
        {
            List <AdminDTO> retVal = new List <AdminDTO>();

            var avioAdmins = await AvioAdminService.GetAdmins();

            foreach (AvioAdmin admin in avioAdmins)
            {
                var user = await AvioAdminService.GetAdminUser(admin.UserId);

                if (admin.AvioCompanyId > 0)
                {
                    var company = await AvioService.GetCompany(admin.AvioCompanyId);

                    if (company != null)
                    {
                        var companyProfile = await AvioService.GetCompanyProfile(company.AvioCompanyProfileId);

                        retVal.Add(new AdminDTO()
                        {
                            Id        = user.Id,
                            Username  = user.UserName,
                            AdminType = "Avio Company Admin",
                            Company   = companyProfile.Name
                        });
                    }
                }
            }

            var carAdmins = await CarAdminService.GetAdmins();

            foreach (CarAdmin admin in carAdmins)
            {
                var user = await CarAdminService.GetAdminUser(admin.UserId);

                if (admin.CarCompanyId > 0)
                {
                    var company = await RentACarService.GetCompany(admin.CarCompanyId);

                    if (company != null)
                    {
                        var companyProfile = await RentACarService.GetCompanyProfile(company.CarCompanyProfileId);

                        retVal.Add(new AdminDTO()
                        {
                            Id        = user.Id,
                            Username  = user.UserName,
                            AdminType = "Car Company Admin",
                            Company   = companyProfile.Name
                        });
                    }
                }
            }

            return(Ok(retVal));
        }
Ejemplo n.º 6
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.º 7
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));
        }
        public async Task <IActionResult> GetFlight(long id)
        {
            if (ModelState.IsValid)
            {
                var flight = await FlightService.GetFlight(id);

                if (flight != null)
                {
                    var company = await AvioService.GetCompany(flight.AvioCompanyId);

                    if (company != null)
                    {
                        var companyProfile = await AvioService.GetCompanyProfile(company.AvioCompanyProfileId);

                        return(Ok(new { flight, company, companyProfile }));
                    }
                }
            }

            return(BadRequest(ModelState));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> GetCompanyProfile()
        {
            if (ModelState.IsValid)
            {
                var user = await AvioAdminService.GetCurrentUser();

                if (user != null)
                {
                    var avioCompany = await AvioService.GetCompany(user.AvioCompanyId);

                    if (avioCompany != null)
                    {
                        var avioCompanyProfile = await AvioService.GetCompanyProfile(avioCompany.AvioCompanyProfileId);

                        return(Ok(new { avioCompany, avioCompanyProfile }));
                    }
                }
            }

            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }