Пример #1
0
        public async Task <IActionResult> CreateItem([FromBody] PriceListItemDTO model)
        {
            if (ModelState.IsValid)
            {
                var user = await AvioAdminService.GetCurrentUser();

                if (user != null)
                {
                    var avioCompany = await AvioService.GetCompany(user.AvioCompanyId);

                    if (avioCompany != null)
                    {
                        PriceListItem item = new PriceListItem()
                        {
                            Name  = model.Name,
                            Price = model.Price
                        };

                        avioCompany.PriceList.Add(item);
                        await AvioService.UpdateCompany(avioCompany);

                        return(Ok(200));
                    }

                    return(BadRequest("Company wasn't found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            return(BadRequest("Not enough data provided."));
        }
Пример #2
0
        public async Task <IActionResult> CreateFlight([FromBody] FlightDTO model)
        {
            if (ModelState.IsValid)
            {
                if (model.Departure > model.Arrival)
                {
                    return(BadRequest("Departure cannot be before landing."));
                }

                if (model.Departure < DateTime.Now)
                {
                    return(BadRequest("Departure cannot be before today's date."));
                }

                var user = await AvioAdminService.GetCurrentUser();

                if (user != null)
                {
                    var avioCompany = await AvioService.GetCompany(user.AvioCompanyId);

                    if (avioCompany != null)
                    {
                        model.DepartureLocation.DestinationId = 0;
                        model.ArrivalLocation.DestinationId   = 0;
                        foreach (Destination d in model.Transit)
                        {
                            d.DestinationId = 0;
                        }

                        var flight = new Flight()
                        {
                            AeroplaneId       = (await AeroplaneService.GetAeroplane(user.AvioCompanyId, model.Aeroplane)).AeroplaneId,
                            Arrival           = model.Arrival,
                            ArrivalLocation   = model.ArrivalLocation,
                            Departure         = model.Departure,
                            DepartureLocation = model.DepartureLocation,
                            AvioCompanyId     = user.AvioCompanyId,
                            Price             = model.Price,
                            Transit           = model.Transit,
                            TravelDistance    = model.TravelDistance,
                            TravelTime        = model.TravelTime
                        };

                        avioCompany.Flights.Add(flight);
                        await AvioService.UpdateCompany(avioCompany);

                        return(Ok(200));
                    }

                    return(BadRequest("Avio company not found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            return(BadRequest("Not enough data provided."));
        }
Пример #3
0
        public async Task <IActionResult> CreateTicket([FromBody] FastReservationFlightTicketDTO ticket)
        {
            if (ModelState.IsValid)
            {
                var user = await AvioAdminService.GetCurrentUser();

                if (user != null)
                {
                    var avioCompany = await AvioService.GetCompany(user.AvioCompanyId);

                    if (avioCompany != null)
                    {
                        FastReservationFlightTicket frft = new FastReservationFlightTicket()
                        {
                            FlightId = ticket.FlightId,
                            Percent  = ticket.Percent
                        };

                        if ((await FlightService.GetFlight(frft.FlightId)) == null)
                        {
                            return(BadRequest("Flight not found."));
                        }

                        avioCompany.FastReservationTickets.Add(frft);
                        await AvioService.UpdateCompany(avioCompany);

                        return(Ok(200));
                    }

                    return(BadRequest("Company wasn't found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

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