public async Task EditReservation(AircraftReservation aircraftReservation)
        {
            await _reservationRepository.UpdateReservation(aircraftReservation);

            //await _reservationRepository.DeleteAsync(aircraftReservation);
            //await _reservationRepository.UpdateAsync(aircraftReservation);
        }
        public async Task <bool> IsValid(AircraftReservation aircraftReservation)
        {
            var reservations = await _reservationRepository.ListAllAsync();

            var exist = reservations.Where(f => f.Intersect(aircraftReservation)).FirstOrDefault();

            if (exist != null && exist.Id != aircraftReservation.Id)
            {
                return(false);
            }
            return(true);
        }
        public async Task <AircraftReservation> AddReservation(AircraftReservation aircraftReservation)
        {
            var reservations = await _reservationRepository.ListAllAsync();

            var exist = reservations.Where(f => f.Intersect(aircraftReservation)).FirstOrDefault();

            if (exist != null)
            {
                return(null);
            }
            await _reservationRepository.AddAsync(aircraftReservation);

            return(aircraftReservation);
        }
        public async Task <Result> Handle(UpdateReservationCommand request, CancellationToken cancellationToken)
        {
            List <string>       errorList           = new List <string>();
            AircraftReservation aircraftReservation = new AircraftReservation();
            var aircraft = _context.Set <Aircraft>().Find(request.FlightReservationModel.AircraftId);

            if (aircraft != null)
            {
                aircraftReservation.AircraftId = aircraft.Id;
            }


            aircraftReservation.AircraftId = request.FlightReservationModel.AircraftId;
            var pilot = _context.Set <Pilot>().Find(request.FlightReservationModel.PilotId);

            if (pilot == null)
            {
                errorList.Add($"Pilot With Id:{request.FlightReservationModel.PilotId} Not Found");
            }
            aircraftReservation.PilotId = pilot.Id;
            //request.FlightReservationModel.CombineTime();
            aircraftReservation.IdNumber   = pilot.IdNumber;
            aircraftReservation.TailNumber = aircraft.TailNumber;
            aircraftReservation.DateFrom   = request.FlightReservationModel.DateFrom;
            aircraftReservation.DateTo     = request.FlightReservationModel.DateTo;
            aircraftReservation.Id         = request.FlightReservationModel.Id;
            var reservations = _context.Set <AircraftReservation>().AsNoTracking().ToList();

            if (reservations.IsFlightReservationValid(aircraftReservation))
            {
                var reservation = _context.Set <AircraftReservation>().Update(aircraftReservation);
                if (reservation != null)
                {
                    int rVal = await _context.SaveChangesAsync(cancellationToken);

                    if (rVal == 0)
                    {
                        errorList.Add($"CreateReservationCommand Save Failed");
                    }
                }
            }
            else
            {
                errorList.Add($"Reservation Already Exist Date Conflict");
            }

            return((errorList.Count > 0) ? Result.Failure(errorList) : Result.Success());
        }
Exemple #5
0
        public async Task ClubServiceTest()
        {
            ImportDataTest import = new ImportDataTest();

            import.InitContext();
            try
            {
                _context = import._context;
                IReservationRepository reservationRepository = new ReservationRepository(_context);
                cr = new ReservationService(reservationRepository);
                AircraftReservation ar = new AircraftReservation();
                ar.DateFrom   = DateTime.Now;
                ar.DateTo     = DateTime.Now.AddHours(1);
                ar.TailNumber = "4xCGC";
                ar.IdNumber   = "123456";
                _context.AircraftReservations.Add(ar);
                _context.SaveChanges();
                var reser = await cr.GetReservation();

                await cr.AddReservation(ar);

                ar.IdNumber = "098765";
                await cr.EditReservation(ar);

                reser = await cr.GetAircraftReservation(ar.TailNumber);

                var aa = await cr.AddReservation(ar);

                AircraftReservation ab = new AircraftReservation();
                ab.DateFrom   = ar.DateTo;
                ab.DateTo     = ab.DateFrom.AddHours(5);
                ab.TailNumber = ar.TailNumber;
                aa            = await cr.AddReservation(ab);

                reser = await cr.GetReservation();

                reser = await cr.GetPilotReservation(ar.IdNumber);

                await cr.DeleteReservation(ar.Id);

                reser = await cr.GetReservation();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Exemple #6
0
        public async Task ClubServiceAddTest()
        {
            ImportDataTest import = new ImportDataTest();

            import.InitContext();
            try
            {
                _context = import._context;
                IReservationRepository reservationRepository = new ReservationRepository(_context);
                IMemberRepository      memberRepository      = new MemberRepository(_context);
                mr = new MemberService(memberRepository);
                Pilot p = await mr.GetPilotById(15);

                cr = new ReservationService(reservationRepository);
                AircraftReservation ar = new AircraftReservation();
                ar.DateFrom   = new DateTime(2019, 08, 29, 14, 23, 00);
                ar.DateTo     = new DateTime(2019, 08, 29, 19, 20, 00);
                ar.TailNumber = "4xCGC";
                ar.IdNumber   = "123456";
                ar.AircraftId = 8;

                ar.ReservationInfo = new UserInfo(p).GetJason();
                var reser = await cr.GetReservation();

                await cr.AddReservation(ar);

                ar.DateFrom = new DateTime(2019, 08, 29, 19, 22, 00);
                ar.DateTo   = new DateTime(2019, 08, 29, 20, 20, 00);
                await cr.AddReservation(ar);

                reser = await cr.GetReservation();

                reser = await cr.GetPilotReservation(ar.IdNumber);

                await cr.DeleteReservation(ar.Id);

                reser = await cr.GetReservation();

                await cr.AddReservation(ar);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Exemple #7
0
        public async Task <bool> Handle(IsReservationValidQuery request, CancellationToken cancellationToken)
        {
            //request.FlightReservationModel.CombineTime();
            AircraftReservation aircraftReservation = _mapper.Map <FlightReservationModel, AircraftReservation>(request.FlightReservationModel);

            //var reservation = _context.Set<AircraftReservation>().Update(aircraftReservation);
            //if (reservation != null)
            //{
            //	result = await _context.SaveChangesAsync(cancellationToken);
            //}
            //return result;

            var reservations = await _context.Set <AircraftReservation>().ToListAsync();

            var exist = reservations.Where(f => f.Intersect(aircraftReservation)).FirstOrDefault();

            if (exist != null && exist.Id != aircraftReservation.Id)
            {
                return(false);
            }
            return(true);
        }
Exemple #8
0
        public static bool IsFlightReservationValid(this List <AircraftReservation> reservations, AircraftReservation reservation)
        {
            var exist = reservations.Where(f => f.Intersect(reservation)).FirstOrDefault();

            if (exist != null && exist.Id != reservation.Id)
            {
                return(false);
            }
            return(true);
        }