public async Task <IActionResult> GetCarsHistory()
        {
            var user = await _userService.GetCurrentUser();

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

                if (reservations != null)
                {
                    List <CarHistoryDTO> carsHistory = new List <CarHistoryDTO>();

                    foreach (CarReservation cr in reservations)
                    {
                        if (DateTime.Now > (cr.PickUpDate.AddDays(-2)))
                        {
                            var vehicle = await _vehicleService.GetVehicleById(cr.VehicleId);

                            if (vehicle != null)
                            {
                                var company = await _rentACarService.GetCompany(vehicle.CarCompanyId);

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

                                    if (companyProfile != null)
                                    {
                                        carsHistory.Add(new CarHistoryDTO()
                                        {
                                            ReservationId  = cr.CarReservationId,
                                            CarCompanyName = companyProfile.Name,
                                            VehicleName    = vehicle.Name,
                                            PickUpDate     = cr.PickUpDate,
                                            ReturnDate     = cr.ReturnDate,
                                            PickUpLocation = cr.PickUpLocation.Name,
                                            ReturnLocation = cr.ReturnLocation.Name
                                        });
                                    }
                                }
                            }
                        }
                    }

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

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

            return(BadRequest("User not found."));
        }
Пример #2
0
        public async Task <IActionResult> GetCompanyProfile()
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var carCompanyProfile = await RentACarService.GetCompanyProfile(carCompany.CarCompanyProfileId);

                        return(Ok(new { carCompany, carCompanyProfile }));
                    }

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

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

            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Пример #3
0
        public async Task <IActionResult> UpdateCompanyProfile([FromBody] CarCompanyProfile model)
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var carCompanyProfile = await RentACarService.GetCompanyProfile(carCompany.CarCompanyProfileId);

                        carCompanyProfile.Name             = model.Name;
                        carCompanyProfile.Address          = model.Address;
                        carCompanyProfile.PromoDescription = model.PromoDescription;

                        await RentACarService.UpdateCompanyProfile(carCompanyProfile);

                        return(Ok(200));
                    }

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

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

            return(BadRequest("Not enough data provided."));
        }
Пример #4
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));
        }
Пример #5
0
        public async Task <IActionResult> GetCarCompanies()
        {
            var carCompanies = await RentACarService.GetCompanies();

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

            foreach (CarCompany carCompany in carCompanies)
            {
                var carCompanyProfile = await RentACarService.GetCompanyProfile(carCompany.CarCompanyProfileId);

                retVal.Add(new CarCompanyDTO()
                {
                    Id          = carCompany.CarCompanyId,
                    Name        = carCompanyProfile.Name,
                    Address     = carCompanyProfile.Address,
                    Description = carCompanyProfile.PromoDescription
                });
            }

            return(Ok(retVal));
        }