Example #1
0
        public async Task <IActionResult> CreateAvioCompany([FromBody] AvioCompanyDTO avioCompanyDTO)
        {
            if (ModelState.IsValid)
            {
                if (await AvioService.CompanyExists(avioCompanyDTO.Name))
                {
                    return(BadRequest("Company already exists with the same name."));
                }

                var profile = new AvioCompanyProfile()
                {
                    Name             = avioCompanyDTO.Name,
                    Address          = avioCompanyDTO.Address,
                    PromoDescription = avioCompanyDTO.Description
                };

                await AvioService.CreateCompany(new AvioCompany(), profile);

                return(Ok(200));
            }

            return(BadRequest("No sufficient data provided."));
        }
Example #2
0
        public async Task <IActionResult> CreateAvioCompany([FromBody] AvioCompanyDTO avioCompanyDTO)
        {
            if (ModelState.IsValid)
            {
                if (await AvioService.CompanyExists(avioCompanyDTO.Name))
                {
                    return(BadRequest("Company already exists with the same name."));
                }

                var profile = new AvioCompanyProfile()
                {
                    Name             = avioCompanyDTO.Name,
                    Address          = avioCompanyDTO.Address,
                    PromoDescription = avioCompanyDTO.Description
                };

                // add destinations
                var dest = new List <Destination>();
                string[,] destinations = { { "Belgrade", "44.786568",  "20.448921"  },
                                           { "Tokyo",    "35.689487",  "139.691711" },
                                           { "New York", "40.712776",  "-74.005974" },
                                           { "Berlin",   "52.520008",  "13.404954"  },
                                           { "Rome",     "41.9028",    "12.4964"    },
                                           { "Zurich",   "47.3768880", "8.541694"   } };

                for (int j = 0; j < destinations.GetLength(0); ++j)
                {
                    Destination destination = new Destination()
                    {
                        Name      = destinations[j, 0],
                        Latitude  = double.Parse(destinations[j, 1], CultureInfo.InvariantCulture),
                        Longitude = double.Parse(destinations[j, 2], CultureInfo.InvariantCulture),
                    };

                    dest.Add(destination);
                }

                AvioCompany company = new AvioCompany()
                {
                    Destinations = dest
                };

                await AvioService.CreateCompany(company, profile);

                // create planes for companies
                var aeroplaneA380 = new Aeroplane()
                {
                    AvioCompanyId = company.AvioCompanyId,
                    Name          = "Airbus A380"
                };

                var aeroplane737 = new Aeroplane()
                {
                    AvioCompanyId = company.AvioCompanyId,
                    Name          = "Boeing 737"
                };

                if (!await AeroplaneService.AeroplaneExists(company.AvioCompanyId, aeroplaneA380.Name))
                {
                    await AeroplaneService.AddAeroplane(aeroplaneA380);
                }

                if (!await AeroplaneService.AeroplaneExists(company.AvioCompanyId, aeroplane737.Name))
                {
                    await AeroplaneService.AddAeroplane(aeroplane737);
                }

                // create seats for planes
                var seatsA380 = new Seats()
                {
                    AeroplaneId = aeroplaneA380.AeroplaneId,
                    SeatCount   = 240,
                    InOneRow    = 6
                };

                var seats737 = new Seats()
                {
                    AeroplaneId = aeroplane737.AeroplaneId,
                    SeatCount   = 320,
                    InOneRow    = 8
                };

                if (!await SeatService.SeatsExist(aeroplaneA380.AeroplaneId))
                {
                    await SeatService.AddSeats(seatsA380);
                }

                if (!await SeatService.SeatsExist(aeroplane737.AeroplaneId))
                {
                    await SeatService.AddSeats(seats737);
                }

                return(Ok(200));
            }

            return(BadRequest("No sufficient data provided."));
        }