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."));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetCompanyReport()
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

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

                    if (carCompany != null)
                    {
                        var companyRating = await RentACarService.GetCompanyRatingAsInteger(carCompany.CarCompanyId);

                        var graph = await RentACarService.GetLastMonthsCarReservations(carCompany.CarCompanyId, 6);

                        return(Ok(new { companyRating, graph }));
                    }

                    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));
        }
Esempio n. 3
0
        public async Task <IActionResult> RemoveOffice(long id)
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

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

                    if (carCompany != null)
                    {
                        var office = carCompany.Offices.Where(o => o.OfficeId == id).SingleOrDefault();

                        if (office != null)
                        {
                            await OfficeService.RemoveOffice(office);

                            return(Ok(200));
                        }

                        return(NotFound("Office wasn't found."));
                    }
                    else
                    {
                        return(BadRequest("Car company wasn't found."));
                    }
                }
            }

            return(BadRequest("No sufficient data provided."));
        }
Esempio n. 4
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));
        }
Esempio n. 5
0
        public async Task <IActionResult> CreateOffice([FromBody] OfficeRequest model)
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

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

                    if (carCompany != null)
                    {
                        var office = new Office()
                        {
                            Address  = model.Address,
                            Location = new Destination()
                            {
                                Name = model.City
                            },
                            CarCompanyId = carCompany.CarCompanyId
                        };

                        carCompany.Offices.Add(office);
                        await RentACarService.UpdateCompany(carCompany);

                        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."));
        }
Esempio n. 6
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."));
        }
Esempio n. 7
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));
        }
Esempio n. 8
0
        public async Task <IActionResult> GetCompanyVehicles()
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

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

                    if (carCompany != null)
                    {
                        var vehicles = carCompany.Vehicles;

                        List <VehicleDTO> vehicleDTOs = new List <VehicleDTO>();
                        foreach (Vehicle v in vehicles)
                        {
                            vehicleDTOs.Add(new VehicleDTO()
                            {
                                VehicleId    = v.VehicleId,
                                Additional   = v.Additional,
                                Baggage      = v.Baggage,
                                CarType      = v.CarType,
                                CostPerDay   = v.CostPerDay,
                                Doors        = v.Doors,
                                Fuel         = v.Fuel,
                                Name         = v.Name,
                                Passangers   = v.Passangers,
                                Transmission = v.Transmission,
                                Rating       = await VehicleService.GetVehicleRatingAsInteger(v.VehicleId)
                            });
                        }

                        return(Ok(vehicleDTOs));
                    }

                    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));
        }
Esempio n. 9
0
        public async Task <IActionResult> GetCompanyOffices()
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

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

                    if (carCompany != null)
                    {
                        var offices = carCompany.Offices;

                        List <OfficeDTO> officeDTOs = new List <OfficeDTO>();
                        foreach (Office o in offices)
                        {
                            officeDTOs.Add(new OfficeDTO()
                            {
                                Location = new DestinationDTO()
                                {
                                    Name      = o.Location.Name,
                                    Latitude  = o.Location.Latitude,
                                    Longitude = o.Location.Longitude
                                },
                                Address  = o.Address,
                                OfficeId = o.OfficeId
                            });
                        }

                        return(Ok(officeDTOs));
                    }
                    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));
        }
Esempio n. 10
0
        public async Task <IActionResult> CreateVehicle([FromBody] VehicleDTO model)
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

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

                    if (carCompany != null)
                    {
                        var vehicle = new Vehicle()
                        {
                            Additional   = model.Additional,
                            Baggage      = model.Baggage,
                            CarCompanyId = carCompany.CarCompanyId,
                            CarType      = model.CarType,
                            CostPerDay   = model.CostPerDay,
                            Doors        = model.Doors,
                            Fuel         = model.Fuel,
                            Name         = model.Name,
                            Passangers   = model.Passangers,
                            Transmission = model.Transmission
                        };

                        carCompany.Vehicles.Add(vehicle);
                        await RentACarService.UpdateCompany(carCompany);

                        return(Ok(200));
                    }
                }
            }

            return(BadRequest("Not enough data provided."));
        }