public UpdateInstructorViewModel(InstructorData entity)
 {
     Id = entity.Id;
     MemberId = entity.MemberId;
     
     CertificateNumber = entity.CertificateNumber;
     Ratings = entity.Ratings;
     InstructOnWeekends = entity.InstructOnWeekends;
     InstructOnWeekdays = entity.InstructOnWeekdays;
     InstructOnWeekdayNights = entity.InstructOnWeekdayNights;
     AvailableForCheckoutsAnnuals = entity.AvailableForCheckoutsAnnuals;
     DesignatedForStageChecks = entity.DesignatedForStageChecks;
     Comments = entity.Comments;
     AuthorizedAircraft = new List<int>();
 }
        public ActionResult UpdateInstructor(UpdateInstructorViewModel viewModel)
        {
            InstructorData instructor = _dataService.GetInstructorInfoByMemberId(viewModel.MemberId);
            if (instructor == null)
                instructor = new InstructorData();

            ProfileCommon profile = ProfileCommon.GetProfile();
            instructor.MemberId = viewModel.MemberId;
            instructor.AvailableForCheckoutsAnnuals = viewModel.AvailableForCheckoutsAnnuals;
            instructor.CertificateNumber = viewModel.CertificateNumber;
            instructor.Ratings = viewModel.Ratings;
            instructor.InstructOnWeekdayNights = viewModel.InstructOnWeekdayNights;
            instructor.InstructOnWeekdays = viewModel.InstructOnWeekdays;
            instructor.InstructOnWeekends = viewModel.InstructOnWeekends;
            instructor.Comments = viewModel.Comments;
            if (User.IsInRole(UserRoles.Admin.ToString()))
            {
                instructor.DesignatedForStageChecks = viewModel.DesignatedForStageChecks;

                if (viewModel.AuthorizedAircraft.Count > 0)
                {
                    if (instructor.AuthorizedAircraft == null)
                        instructor.AuthorizedAircraft = new List<InstructorAuthorization>();

                    foreach (var acId in viewModel.AuthorizedAircraft)
                    {
                        if (instructor.AuthorizedAircraft.Any(aa => aa.AircraftId == acId))
                            continue;

                        InstructorAuthorization auth = new InstructorAuthorization()
                        {
                            AircraftId = acId,
                            InstructorId = viewModel.Id,
                            AuthorizedOn = DateTime.Now,
                            AuthorizedById = profile.MemberId
                        };

                        instructor.AuthorizedAircraft.Add(auth);
                    }
                }
            }

            _dataService.SaveInstructor(instructor);


            //Member member = _dataService.GetMember(instructor.MemberId);

            //InstructorViewModel instructorVM = new InstructorViewModel()
            //{
            //    MemberId = instructor.MemberId,
            //    AltPhone = member.Phone,
            //    AvailableForCheckoutsAnnuals = instructor.AvailableForCheckoutsAnnuals,
            //    InstructOnWeekdayNights = instructor.InstructOnWeekdayNights,
            //    InstructOnWeekdays = instructor.InstructOnWeekdays,
            //    InstructOnWeekends = instructor.InstructOnWeekends,
            //    CeritifcateNumber = instructor.CertificateNumber,
            //    Comments = instructor.Comments,
            //    DesignatedForStageChecks = instructor.DesignatedForStageChecks,
            //    Email = member.Login.Email,
            //    FullName = member.FullName,
            //    Id = instructor.Id,
            //    Phone = member.Phone,
            //    Ratings = instructor.Ratings
            //};

            return RedirectToAction("InstructorDetails", new { memberId = instructor.MemberId });

        }
Example #3
0
 public void SaveInstructor(InstructorData instructor)
 {
     if(instructor.Id > 0)
         _repository.Attach(instructor);
     else
         _repository.Add(instructor);
     _repository.UnitOfWork.SaveChanges();
 }
Example #4
0
        public void ImportInstructors()
        {
            IEnumerator<NtfcDataSet.InstructorIDRow> rows = _dataSet.InstructorID.GetEnumerator();
            Role instructorRole = _dbContext.Roles.First(r => r.Name.Contains("Instructor"));

            while (rows.MoveNext())
            {
                NtfcDataSet.InstructorIDRow row = rows.Current;

                if (row.Instructor_MID == "537" || row.Instructor_MID == "547" || row.Instructor_MID == "734" || row.Instructor_MID == "735" || row.Instructor_MID == "999")
                    continue;

                InstructorData instructor = new InstructorData();
                if (!row.IsannualsNull())
                    instructor.AvailableForCheckoutsAnnuals = row.annuals.ToLower() == "yes" ? true : false;
                else
                    instructor.AvailableForCheckoutsAnnuals = false;
                instructor.CertificateNumber = String.Empty;
                if(!row.IsnotesNull())
                    instructor.Comments = row.notes;                                                         
                instructor.DesignatedForStageChecks = false;
                if (!row.IsdaysNull())
                    instructor.InstructOnWeekdays = row.days.ToLower() == "yes" ? true : false;
                else
                    instructor.InstructOnWeekdays = false;
                if (!row.IseveningsNull())
                    instructor.InstructOnWeekdayNights = row.evenings.ToLower() == "yes" ? true : false;
                else
                    instructor.InstructOnWeekdayNights = false;
                if (!row.IsweekendsNull())
                    instructor.InstructOnWeekends = row.weekends.ToLower() == "yes" ? true : false;
                else
                    instructor.InstructOnWeekends = false;
                instructor.Ratings = String.Empty;

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

                Member member = login.ClubMember.First();
                member.Roles.Add(instructorRole);
                instructor.Member = member;
                _dbContext.InstructorData.Add(instructor);

                _dbContext.SaveChanges();
            }
        }