コード例 #1
0
 public void AddCheckout(PilotCheckout checkout)
 {
     _repository.Add<PilotCheckout>(checkout);
     _repository.UnitOfWork.SaveChanges();
 }
コード例 #2
0
        public ActionResult AddCheckout(AddCheckoutViewModel viewModel)
        {
            PilotCheckout checkout = new PilotCheckout();
            checkout.AircraftId = viewModel.AircraftId;
            checkout.PilotId = viewModel.PilotId;
            checkout.InstructorId = viewModel.InstructorId;
            checkout.CheckoutDate = viewModel.CheckoutDate;

            _dataService.AddCheckout(checkout);

            return PilotReview(viewModel.PilotId);
        }
コード例 #3
0
        public void ImportCheckouts()
        {
            IDictionary<string, List<int>> acMap = new Dictionary<string, List<int>>();
            List<int> ids = _dbContext.Aircraft.Where(a => a.RegistrationNumber == "N49649" || a.RegistrationNumber == "N4952B")
                .Select(a => a.Id).ToList();
            acMap.Add("C150", ids);
            acMap.Add("C152", ids);

            ids = _dbContext.Aircraft.Where(a => a.RegistrationNumber == "N73192")
                .Select(a => a.Id).ToList();
            acMap.Add("C172", ids);

            ids = _dbContext.Aircraft.Where(a => a.RegistrationNumber == "N2099V")
                .Select(a => a.Id).ToList();
            acMap.Add("C120", ids);

            ids = _dbContext.Aircraft.Where(a => a.RegistrationNumber == "N8142H")
                .Select(a => a.Id).ToList();
            acMap.Add("PA28-161", ids);
            acMap.Add("PA28-181", ids);

            ids = _dbContext.Aircraft.Where(a => a.RegistrationNumber == "N8185E")
                .Select(a => a.Id).ToList();
            acMap.Add("PA28-R201", ids);


            List<Member> members = _dbContext.Members.Where(m => m.Status == "Active")
                .Include(m => m.Login)
                .ToList();

            foreach (var member in members)
            {
                List<PilotCheckout> checkouts = new List<PilotCheckout>();

                List<NtfcDataSet.CheckoutRow> srcRows = _dataSet.Checkout
                    .Where(c => c.Member_ID == member.Login.MemberPIN)
                    .OrderByDescending(c => c.Checkout_Date)
                    .ToList();

                if (member.Login.MemberPIN == "735")
                    System.Diagnostics.Debug.Write("735");

                foreach (var row in srcRows)
                {
                    if (!acMap.ContainsKey(row.AC_Type))
                        continue;

                    List<int> acIds = acMap[row.AC_Type];
                    foreach (int id in acIds)
                    {
                        // skip duplicates
                        if (checkouts.Any(c => c.AircraftId == id))
                            continue;
                        

                        PilotCheckout pilotCheckout = new PilotCheckout();
                        pilotCheckout.AircraftId = id;
                        pilotCheckout.CheckoutDate = row.Checkout_Date;

                        pilotCheckout.PilotId = member.Id;

                        Login instructorLogin = _dbContext.Logins.Where(l => l.MemberPIN == row.Instructor_MID).FirstOrDefault();
                        if (instructorLogin == null)
                            continue;

                        int instructorId = _dbContext.Members.First(m => m.LoginId == instructorLogin.Id).Id;
                        pilotCheckout.InstructorId = instructorId;

                        checkouts.Add(pilotCheckout);
                        _dbContext.PilotCheckouts.Add(pilotCheckout);          
                    }
                }
            }


            //IEnumerator<NtfcDataSet.CheckoutRow> rows = _dataSet.Checkout.GetEnumerator();
            //while (rows.MoveNext())
            //{
            //    NtfcDataSet.CheckoutRow row = rows.Current;

            //    if (!acMap.ContainsKey(row.AC_Type))
            //        continue;

            //    List<int> acIds = acMap[row.AC_Type];

            //    foreach (int id in acIds)
            //    {
            //        PilotCheckout pilotCheckout = new PilotCheckout();
            //        pilotCheckout.AircraftId = id;
            //        pilotCheckout.CheckoutDate = row.Checkout_Date;

            //        Login pilotLogin = _dbContext.Logins.Where(l => l.MemberPIN == row.Member_ID).FirstOrDefault();
            //        if (pilotLogin == null)
            //            continue;
            //        int pilotId = _dbContext.Members.First(m => m.LoginId == pilotLogin.Id).Id;
            //        pilotCheckout.PilotId = pilotId;

            //        Login instructorLogin = _dbContext.Logins.Where(l => l.MemberPIN == row.Instructor_MID).FirstOrDefault();
            //        if (instructorLogin == null)
            //            continue;
            //        int instructorId = _dbContext.Members.First(m => m.LoginId == instructorLogin.Id).Id;
            //        pilotCheckout.InstructorId = instructorId;
            //        _dbContext.PilotCheckouts.Add(pilotCheckout);
            //    }
            //}

            _dbContext.SaveChanges();
        }