Exemplo n.º 1
0
        public void SaveReservation(Reservation reservation)
        {
            if (reservation.Id == 0)
                _repository.Add<Reservation>(reservation);
            else
                _repository.Attach<Reservation>(reservation);

            _repository.UnitOfWork.SaveChanges();
        }
Exemplo n.º 2
0
 public void DeleteReservation(Reservation reservation)
 {
     _repository.Delete<Reservation>(reservation);
     _repository.UnitOfWork.SaveChanges();
 }
Exemplo n.º 3
0
        public void ImportSchedule()
        {
            //List<NtfcDataSet.ScheduleRow> rows = _dataSet.Schedule.Where(r => 
            //    r.Sched_Date > DateTime.Now.Subtract(new TimeSpan(90, 0, 0, 0)) && 
            //    r.AC01_MID != null && r.AC01_MID != String.Empty)
            //    .ToList();

            TimeSpan scheduleBackImport = new TimeSpan(30, 0, 0, 0);
            //-------------- schedule for the N2099V -----------
            string acRegNum = "N2099V";
            var query = from s in _dataSet.Schedule
                        where s.Sched_Date > DateTime.Now.Subtract(scheduleBackImport) &&
                        s.AC01_MID != null &&
                        s.AC01_MID.Trim() != String.Empty
                        orderby s.Sched_Date, s.Sched_Time
                        select s;

            List<NtfcDataSet.ScheduleRow> rows = query.ToList();

            for (int i = 0; i < rows.Count; )
            {
                string username = rows[i].AC01_MID;
                Login login = _dbContext.Logins.Where(l => l.MemberPIN == username)
                    .Include(l => l.ClubMember)
                    .FirstOrDefault();

                if (login == null)
                {
                    i++;
                    continue;
                }//throw new ArgumentException("Unable to find login for member " + username);

                int memberId = login.ClubMember.First().Id;

                Reservation reservation = new Reservation();
                reservation.StartDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time);
                reservation.EndDate = reservation.StartDate.Add(new TimeSpan(0, 30, 0));
                reservation.AircraftId = _dbContext.Aircraft.First(a => a.RegistrationNumber == acRegNum).Id;
                reservation.MemberId = memberId;
                while (++i < rows.Count && username == rows[i].AC01_MID)
                {
                    reservation.EndDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time)
                        .Add(new TimeSpan(0, 30, 0));
                }
                _dbContext.Reservations.Add(reservation);
            }
            _dbContext.SaveChanges();

            //-------- N4952B -----------
            acRegNum = "N4952B";
            query = from s in _dataSet.Schedule
                    where s.Sched_Date > DateTime.Now.Subtract(scheduleBackImport) &&
                        s.AC03_MID != null &&
                        s.AC03_MID.Trim() != String.Empty
                        orderby s.Sched_Date, s.Sched_Time
                        select s;

            rows = query.ToList();

            for (int i = 0; i < rows.Count; )
            {
                string username = rows[i].AC03_MID;
                Login login = _dbContext.Logins.Where(l => l.MemberPIN == username)
                    .Include(l => l.ClubMember)
                    .FirstOrDefault();

                if (login == null)
                {
                    i++;
                    continue;
                }//throw new ArgumentException("Unable to find login for member " + username);

                int memberId = login.ClubMember.First().Id;

                Reservation reservation = new Reservation();
                reservation.StartDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time);
                reservation.EndDate = reservation.StartDate.Add(new TimeSpan(0, 30, 0));
                reservation.AircraftId = _dbContext.Aircraft.First(a => a.RegistrationNumber == acRegNum).Id;
                reservation.MemberId = memberId;
                while (++i < rows.Count && username == rows[i].AC03_MID)
                {
                    reservation.EndDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time)
                        .Add(new TimeSpan(0, 30, 0));
                }
                _dbContext.Reservations.Add(reservation);
            }
            _dbContext.SaveChanges();

            //-------- N8185E -----------
            acRegNum = "N8185E";
            query = from s in _dataSet.Schedule
                    where s.Sched_Date > DateTime.Now.Subtract(scheduleBackImport) &&
                    s.AC04_MID != null &&
                    s.AC04_MID.Trim() != String.Empty
                    orderby s.Sched_Date, s.Sched_Time
                    select s;

            rows = query.ToList();

            for (int i = 0; i < rows.Count; )
            {
                string username = rows[i].AC04_MID;
                Login login = _dbContext.Logins.Where(l => l.MemberPIN == username)
                    .Include(l => l.ClubMember)
                    .FirstOrDefault();

                if (login == null)
                {
                    i++;
                    continue;
                }//throw new ArgumentException("Unable to find login for member " + username);

                int memberId = login.ClubMember.First().Id;

                Reservation reservation = new Reservation();
                reservation.StartDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time);
                reservation.EndDate = reservation.StartDate.Add(new TimeSpan(0, 30, 0));
                reservation.AircraftId = _dbContext.Aircraft.First(a => a.RegistrationNumber == acRegNum).Id;
                reservation.MemberId = memberId;
                while (++i < rows.Count && username == rows[i].AC04_MID)
                {
                    reservation.EndDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time)
                        .Add(new TimeSpan(0, 30, 0));
                }
                _dbContext.Reservations.Add(reservation);
            }
            _dbContext.SaveChanges();

            //-------- N8142H -----------
            acRegNum = "N8142H";
            query = from s in _dataSet.Schedule
                    where s.Sched_Date > DateTime.Now.Subtract(scheduleBackImport) &&
                        s.AC07_MID != null &&
                        s.AC07_MID.Trim() != String.Empty
                        orderby s.Sched_Date, s.Sched_Time
                        select s;

            rows = query.ToList();

            for (int i = 0; i < rows.Count; )
            {
                string username = rows[i].AC07_MID;
                Login login = _dbContext.Logins.Where(l => l.MemberPIN == username)
                    .Include(l => l.ClubMember)
                    .FirstOrDefault();

                if (login == null)
                {
                    i++;
                    continue;
                }//throw new ArgumentException("Unable to find login for member " + username);

                int memberId = login.ClubMember.First().Id;

                Reservation reservation = new Reservation();
                reservation.StartDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time);
                reservation.EndDate = reservation.StartDate.Add(new TimeSpan(0, 30, 0));
                reservation.AircraftId = _dbContext.Aircraft.First(a => a.RegistrationNumber == acRegNum).Id;
                reservation.MemberId = memberId;
                while (++i < rows.Count && username == rows[i].AC07_MID)
                {
                    reservation.EndDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time)
                        .Add(new TimeSpan(0, 30, 0));
                }
                _dbContext.Reservations.Add(reservation);
            }
            _dbContext.SaveChanges();

            //-------- N49649 -----------
            acRegNum = "N49649";
            query = from s in _dataSet.Schedule
                    where s.Sched_Date > DateTime.Now.Subtract(scheduleBackImport) &&
                    s.AC09_MID != null &&
                    s.AC09_MID.Trim() != String.Empty
                    orderby s.Sched_Date, s.Sched_Time
                    select s;

            rows = query.ToList();

            for (int i = 0; i < rows.Count; )
            {
                string username = rows[i].AC09_MID;
                Login login = _dbContext.Logins.Where(l => l.MemberPIN == username)
                    .Include(l => l.ClubMember)
                    .FirstOrDefault();

                if (login == null)
                {
                    i++;
                    continue;
                }//throw new ArgumentException("Unable to find login for member " + username);

                int memberId = login.ClubMember.First().Id;

                Reservation reservation = new Reservation();
                reservation.StartDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time);
                reservation.EndDate = reservation.StartDate.Add(new TimeSpan(0, 30, 0));
                reservation.AircraftId = _dbContext.Aircraft.First(a => a.RegistrationNumber == acRegNum).Id;
                reservation.MemberId = memberId;
                while (++i < rows.Count && username == rows[i].AC09_MID)
                {
                    reservation.EndDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time)
                        .Add(new TimeSpan(0, 30, 0));
                }
                _dbContext.Reservations.Add(reservation);
            }
            _dbContext.SaveChanges();

            //-------- N73192 -----------
            acRegNum = "N73192";
            query = from s in _dataSet.Schedule
                    where s.Sched_Date > DateTime.Now.Subtract(scheduleBackImport) &&
                    s.AC10_MID != null &&
                    s.AC10_MID.Trim() != String.Empty
                    orderby s.Sched_Date, s.Sched_Time
                    select s;

            rows = query.ToList();

            for (int i = 0; i < rows.Count; )
            {
                string username = rows[i].AC10_MID;
                Login login = _dbContext.Logins.Where(l => l.MemberPIN == username)
                    .Include(l => l.ClubMember)
                    .FirstOrDefault();

                if (login == null)
                {
                    i++;
                    continue;
                }//throw new ArgumentException("Unable to find login for member " + username);

                int memberId = login.ClubMember.First().Id;

                Reservation reservation = new Reservation();
                reservation.StartDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time);
                reservation.EndDate = reservation.StartDate.Add(new TimeSpan(0, 30, 0));
                reservation.AircraftId = _dbContext.Aircraft.First(a => a.RegistrationNumber == acRegNum).Id;
                reservation.MemberId = memberId;
                while (++i < rows.Count && username == rows[i].AC10_MID)
                {
                        reservation.EndDate = ParseDateTime(rows[i].Sched_Date, rows[i].Sched_Time)
                            .Add(new TimeSpan(0, 30, 0));
                }
                _dbContext.Reservations.Add(reservation);
            }
            _dbContext.SaveChanges();         
        }