Esempio n. 1
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. 2
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."));
        }