Esempio n. 1
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."));
        }
        public static async Task AddDefaultCarCompanies(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            var rentACarService = serviceProvider.GetRequiredService <RentACarService>();

            string[,] carCompanies = { { "Fox Rent A Car",       "Boulevard of Broken Dreams 33",  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis arcu et ipsum semper consectetur. Donec sit amet magna augue. Curabitur rhoncus, lacus ut rhoncus pretium, lectus risus sagittis urna, vel imperdiet velit nunc sed sem. Suspendisse ac rutrum neque. Quisque sed mollis enim. Etiam quis eros tempor, dapibus justo eu, blandit libero. Curabitur elementum tincidunt eros ut luctus. Etiam nec felis consequat, tincidunt nisl non, posuere magna. Mauris vel ipsum mauris. Phasellus non ante ornare, tristique est vitae, fringilla odio. Vivamus ultricies lacus et pharetra placerat. Phasellus auctor efficitur sem eget convallis. Sed eu ante sapien. Fusce ac enim in libero rhoncus blandit ut lacinia eros. Sed rhoncus non libero eu hendrerit. Maecenas eget venenatis nisi, vel blandit dolor. "                        },
                                       { "Europcar",             "Boulevard of Awesome Dreams 22", "Aenean consectetur eleifend nulla, ac rutrum turpis vulputate vel. Praesent posuere magna turpis, et tincidunt libero dapibus ac. Nullam euismod felis eget lacus placerat, id fringilla neque sagittis. Curabitur a aliquam ante, quis pharetra tellus. Donec ante dui, sollicitudin quis ex non, tristique tincidunt urna. Duis blandit bibendum ex. In nulla ligula, consectetur quis diam at, laoreet sagittis nisl. Curabitur imperdiet laoreet purus ullamcorper pretium. Pellentesque a sodales nisl, ac laoreet enim. Fusce rhoncus non libero ut tempor. Phasellus eget condimentum sapien, ac fringilla nulla. Duis volutpat tortor ac iaculis faucibus. Aenean dignissim massa dolor, vel efficitur orci molestie a. Cras dignissim molestie nisl, sit amet euismod elit commodo a. Curabitur blandit bibendum fermentum. Fusce vel odio quam." },
                                       { "Advantage Rent-A-Car", "Damians House 11",               "Phasellus posuere ligula eget mollis hendrerit. Donec finibus orci ut porttitor semper. Ut nec porta augue. Sed libero est, vestibulum tincidunt ipsum eget, laoreet commodo elit. Quisque accumsan aliquam tempus. Ut vestibulum gravida magna, eget semper felis rutrum ornare. In quis lobortis dolor, sed hendrerit velit. Nullam lacinia in nulla non vestibulum. Ut ipsum leo, ullamcorper vel mollis vitae, tempor vitae risus. Maecenas id vulputate purus, id congue erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent a ullamcorper orci. Duis eu purus feugiat, euismod urna sed, commodo purus. Morbi quis tortor id dui dictum lacinia. Proin porttitor est id turpis pharetra condimentum. Integer at magna nec leo placerat tincidunt sed quis quam. "                           },
                                       { "E-Z Rent-A-Car",       "Neverlands Street 44",           "Donec cursus luctus est, malesuada tempor tellus laoreet eget. Vestibulum viverra elit a ex gravida lobortis. Nulla aliquet nunc nec aliquam facilisis. Quisque nec sapien ultricies, tempus leo in, sollicitudin arcu. Integer in gravida ipsum. Maecenas vel ex a quam pulvinar scelerisque ac vel turpis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Pellentesque eleifend sollicitudin velit sed fermentum. Donec congue nisi mi. Suspendisse at facilisis tortor, sagittis mattis justo. Curabitur molestie dictum venenatis. In maximus cursus orci sed iaculis. Praesent posuere vulputate elementum. "                                                                                                                                                                                                } };

            for (int i = 0; i < carCompanies.GetLength(0); ++i)
            {
                var companyExists = await rentACarService.CompanyExists(carCompanies[i, 0]);

                if (!companyExists)
                {
                    CarCompanyProfile profile = new CarCompanyProfile()
                    {
                        Name             = carCompanies[i, 0],
                        Address          = carCompanies[i, 1],
                        PromoDescription = carCompanies[i, 2]
                    };

                    await rentACarService.CreateCompany(profile);
                }
            }
        }
Esempio n. 3
0
        public async Task CreateCompany(CarCompanyProfile profile)
        {
            var result = await _context.CarCompanyProfiles.AddAsync(profile);

            await _context.SaveChangesAsync();

            long carCompanyProfileId = result.Entity.CarCompanyProfileId;
            await _context.CarCompanies.AddAsync(new CarCompany()
            {
                CarCompanyProfileId = carCompanyProfileId
            });

            await _context.SaveChangesAsync();
        }
Esempio n. 4
0
        public async Task <IActionResult> CreateCarCompany([FromBody] CarCompanyDTO carCompanyDTO)
        {
            if (ModelState.IsValid)
            {
                if (await RentACarService.CompanyExists(carCompanyDTO.Name))
                {
                    return(BadRequest("Company already exists."));
                }

                var profile = new CarCompanyProfile()
                {
                    Name             = carCompanyDTO.Name,
                    Address          = carCompanyDTO.Address,
                    PromoDescription = carCompanyDTO.Description
                };

                await RentACarService.CreateCompany(profile);

                return(Ok(200));
            }

            return(BadRequest("No sufficient data provided."));
        }
Esempio n. 5
0
        public async Task <IActionResult> GetCompanyDetails(long id)
        {
            CarCompany company = await CarService.GetCompany(id);

            CarCompanyProfile companyProfile = new CarCompanyProfile();

            CarCompanyProfileDTO carCompanyProfileDTO = new CarCompanyProfileDTO();

            List <Office>  officeList    = company.Offices;
            List <Vehicle> vehicleList   = company.Vehicles;
            List <int>     vehicleRating = new List <int>();

            foreach (var vehicle in vehicleList)
            {
                vehicleRating.Add(await VehicleService.GetVehicleRatingAsInteger(vehicle.VehicleId));
            }

            int carCompanyRatingPicture = 0;

            if (ModelState.IsValid)
            {
                List <OfficeDTO> officeDTOList = new List <OfficeDTO>();

                for (int i = 0; i < officeList.Count; i++)
                {
                    OfficeDTO officeDTO = new OfficeDTO();

                    DestinationDTO destinationDTO = new DestinationDTO();

                    destinationDTO.Latitude  = officeList[i].Location.Latitude;
                    destinationDTO.Longitude = officeList[i].Location.Longitude;
                    destinationDTO.Name      = officeList[i].Location.Name;

                    officeDTO.OfficeId = officeList[i].OfficeId;
                    officeDTO.Location = destinationDTO;
                    officeDTO.Address  = officeList[i].Address;

                    officeDTOList.Add(officeDTO);
                }

                List <VehicleDTO> vehicleDTOList = new List <VehicleDTO>();

                for (int i = 0; i < vehicleList.Count; i++)
                {
                    VehicleDTO vehicleDTO = new VehicleDTO();

                    vehicleDTO.Additional   = vehicleList[i].Additional;
                    vehicleDTO.Baggage      = vehicleList[i].Baggage;
                    vehicleDTO.CarType      = vehicleList[i].CarType;
                    vehicleDTO.CostPerDay   = vehicleList[i].CostPerDay;
                    vehicleDTO.Doors        = vehicleList[i].Doors;
                    vehicleDTO.Fuel         = vehicleList[i].Fuel;
                    vehicleDTO.Name         = vehicleList[i].Name;
                    vehicleDTO.Passangers   = vehicleList[i].Passangers;
                    vehicleDTO.Rating       = vehicleRating[i];
                    vehicleDTO.Transmission = vehicleList[i].Transmission;
                    vehicleDTO.VehicleId    = vehicleList[i].VehicleId;
                    vehicleDTO.Additional   = vehicleList[i].Additional;

                    vehicleDTOList.Add(vehicleDTO);
                }

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

                companyProfile = await CarService.GetCompanyProfile(id);

                carCompanyRatingPicture = await CarService.GetCompanyRatingAsInteger(id);

                carCompanyProfileDTO.Id            = company.CarCompanyId;
                carCompanyProfileDTO.Name          = companyProfile.Name;
                carCompanyProfileDTO.RatingPicture = carCompanyRatingPicture;
                carCompanyProfileDTO.Address       = companyProfile.Address;
                carCompanyProfileDTO.Description   = companyProfile.PromoDescription;
                carCompanyProfileDTO.OfficeList    = officeList;
                carCompanyProfileDTO.VehicleList   = vehicleDTOList;
                carCompanyProfileDTO.Offices       = allOfficies;

                return(Ok(new { carCompanyProfileDTO }));
            }
            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Esempio n. 6
0
 public async Task UpdateCompanyProfile(CarCompanyProfile carCompanyProfile)
 {
     await _rentACarRepository.UpdateCompanyProfile(carCompanyProfile);
 }
Esempio n. 7
0
 public async Task CreateCompany(CarCompanyProfile profile)
 {
     await _rentACarRepository.CreateCompany(profile);
 }
Esempio n. 8
0
 public async Task UpdateCompanyProfile(CarCompanyProfile profile)
 {
     _context.CarCompanyProfiles.Update(profile);
     await _context.SaveChangesAsync();
 }