Example #1
0
        public async Task <PilotDTO> CreatePilot(PilotDTO pilot)
        {
            if (pilot != null)
            {
                if (await unit.PilotsRepo.GetEntityById(pilot.Id) != null)
                {
                    throw new ArgumentOutOfRangeException("Such user exsists!");
                }
                Pilot newPilot = mapper.Map <PilotDTO, Pilot>(pilot);
                if (newPilot == null || newPilot.Name == null || newPilot.Surname == null)
                {
                    throw new AutoMapperMappingException("Couldn't map PilotDTO into Pilot");
                }

                var result = await unit.PilotsRepo.Insert(newPilot);

                await unit.SaveChangesAsync();

                return(mapper.Map <Pilot, PilotDTO>(result) ?? throw new AutoMapperMappingException("Error: Can't map the pilot into pilotDTO"));
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Example #2
0
        public async Task <PlaneTypeDTO> CreatePlaneType(PlaneTypeDTO planeType)
        {
            if (planeType != null)
            {
                PlaneType newPlaneType = mapper.Map <PlaneTypeDTO, PlaneType>(planeType) ?? throw new AutoMapperMappingException("Error: Can't map the PlaneTypeDTO into PlaneType");;
                var       result       = await unit.PlaneTypesRepo.Insert(newPlaneType);

                await unit.SaveChangesAsync();

                return(mapper.Map <PlaneType, PlaneTypeDTO>(result) ?? throw new AutoMapperMappingException("Error: Can't map the planeType into planeTypeDTO"));
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Example #3
0
        public async Task <StewardessDTO> CreateStewardess(StewardessDTO stewardess)
        {
            if (stewardess != null)
            {
                Stewardess newStewardess = mapper.Map <StewardessDTO, Stewardess>(stewardess) ?? throw new AutoMapperMappingException("Error: Can't map the stewardessDTO into stewardess");
                var        result        = await unit.StewardessesRepo.Insert(newStewardess);

                await unit.SaveChangesAsync();

                return(mapper.Map <Stewardess, StewardessDTO>(result) ?? throw new AutoMapperMappingException("Error: Can't map the stewardess into stewardessDTO"));
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Example #4
0
        public async Task <DepartureDTO> CreateDeparture(DepartureDTO departure)
        {
            if (departure != null)
            {
                Departure newDepart = mapper.Map <DepartureDTO, Departure>(departure) ?? throw new AutoMapperMappingException("Error: Can't map the departureDTO into departure");
                await unit.DeparturesRepo.Insert(newDepart);

                await unit.SaveChangesAsync();

                return(departure);
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
        public async Task <FlightDTO> CreateFlight(FlightDTO flight)
        {
            if (flight == null)
            {
                Flight newFlight = mapper.Map <FlightDTO, Flight>(flight) ?? throw new AutoMapperMappingException("Error: Can't map the flightDTO into flight");

                var result = await unit.FlightsRepo.Insert(newFlight);

                await unit.SaveChangesAsync();

                return(mapper.Map <Flight, FlightDTO>(result) ?? throw new AutoMapperMappingException("Error: Can't map the flight into flightDTO"));
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Example #6
0
        public async Task <PlaneDTO> CreatePlane(int departId, PlaneDTO value)
        {
            var departure = await unit.DeparturesRepo.GetEntityById(departId);

            if (departure != null)
            {
                var plane = mapper.Map <PlaneDTO, Plane>(value) ?? throw new AutoMapperMappingException("Error: Can't map the planeDTO into plane");

                departure.PlaneItem = plane;
                var result = await unit.DeparturesRepo.Update(departure);

                await unit.SaveChangesAsync();

                return(mapper.Map <Plane, PlaneDTO>(result.PlaneItem) ?? throw new AutoMapperMappingException("Error: Can't map the plane into planeDTO"));
            }
            else
            {
                throw new Exception("Error: Can't find such departure!");
            }
        }
Example #7
0
        public async Task <CrewDTO> CreateCrew(int departId, CrewDTO value)
        {
            var departure = await unit.DeparturesRepo.GetEntityById(departId);

            if (departure != null)
            {
                var crew = mapper.Map <CrewDTO, Crew>(value) ?? throw new AutoMapperMappingException("Error: Can't map the crewDTO into crew");
                var s    = await unit.CrewRepo.Insert(crew);

                departure.CrewItem = crew ?? throw new Exception("Error: Can't add this crew to the departure!");
                var d = await unit.DeparturesRepo.Update(departure);

                await unit.SaveChangesAsync();

                return(value);
            }
            else
            {
                throw new Exception("Error: Can't find such departure!");
            }
        }
Example #8
0
        public async Task <TicketDTO> CreateTicket(int flightId, TicketDTO value)
        {
            var flight = await unit.FlightsRepo.GetEntityById(flightId);

            if (flight != null)
            {
                var ticket = mapper.Map <TicketDTO, Ticket>(value) ?? throw new AutoMapperMappingException("Error: Can't map the TicketDTO into Ticket");
                if (flight.Tickets.Contains(ticket))
                {
                    throw new Exception("Error: Can't add this ticket to the the flight!");
                }
                flight.Tickets.Add(ticket);
                var result = await unit.FlightsRepo.Update(flight);

                await unit.SaveChangesAsync();

                return(mapper.Map <Ticket, TicketDTO>(ticket) ?? throw new AutoMapperMappingException("Error: Can't map the Ticket into TicketDTO"));
            }
            else
            {
                throw new Exception("Error: Can't find such flight!");
            }
        }