示例#1
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));
        }
示例#2
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."));
        }
示例#3
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));
        }
示例#4
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."));
        }
示例#5
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."));
        }
示例#6
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));
        }
示例#7
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));
        }
示例#8
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."));
        }