Ejemplo n.º 1
0
 /// <summary>
 /// Maps the model from the View Model for saving a new CCA to the database.
 /// </summary>
 /// <param name="ccaVm"></param>
 /// <param name="student"></param>
 private CCA MapModel(CCAViewModel ccaVm, Student student)
 {
     try
     {
         Mapper.CreateMap<CCAViewModel, CCA>();
         var cca = Mapper.Map<CCAViewModel, CCA>(ccaVm);
         cca.ApplicationSubmissionDate = DateTime.Now;
         cca.StudentID = student.ID;
         cca.EnrollmentLocationID = student.EnrollmentLocationID;
         cca.EnrollmentLocationSchoolNamesID = student.EnrollmentLocationSchoolNamesID;
         return cca;
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Helpers to populate lists for Creating CCAs.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private CCAViewModel GetSelectLists(CCAViewModel model)
        {
            try
            {
                var leaId = model.EnrollmentLocationID;
                if (leaId == 0 || leaId == 1)
                {
                    model.CounselorList = new List<SelectListItem>();
                }
                else
                {
                    var schoolID = db.Students.Where(m => m.UserId == model.UserId).Select(m => m.EnrollmentLocationSchoolNamesID).FirstOrDefault();

                    model.CounselorList = db.Counselors.Where(m => m.EnrollmentLocationSchoolNameID == schoolID).Select(f => new SelectListItem
                    {
                        Value = f.ID.ToString(),
                        Text = f.FirstName + " " + f.LastName
                    });

                    // Add a item to add new counselor to list.

                    model.CounselorList = model.CounselorList.Concat(new[] {new SelectListItem
                    {
                        Value = "0",
                        Text = "Counselor Not Listed."
                    }
                    });
                }

                model.ExcessiveFEDReasonList = db.ExcessiveFEDReasons.Select(f => new SelectListItem
                {
                    Value = f.ID.ToString(),
                    Text = f.Reason
                });

                model.Session = db.Session.Where(x => x.Name != "All" && x.IsActive).Select(f => new SelectListItem
                {
                    Value = f.ID.ToString(),
                    Text = f.Name
                });

                model.CourseCategory = new List<SelectListItem>();

                model.OnlineCourse = new List<SelectListItem>();

                model.CourseCredit = new List<SelectListItem>();

                return model;
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates Counselor if no matching counselor was found in database.
        /// </summary>
        /// <param name="ccaVm"></param>
        /// <param name="cca"></param>
        /// <param name="student"></param>
        /// <returns></returns>
        private async Task CounselorCreate(CCAViewModel ccaVm, CCA cca, Student student)
        {
            // Homeschoolers will be assigned Counselor at the ID=0 entry (now Cory Kanth)
            try
            {
                if (cca.EnrollmentLocationID == GlobalVariables.PRIVATESCHOOLID || (cca.EnrollmentLocationID != GlobalVariables.HOMESCHOOLID && cca.CounselorID == 0))
                {
                    int counselorId = 0;
                    // Check for existing counselor entry by email address
                    if (ccaVm.CounselorEmail != null)
                    {
                        counselorId = await db.Counselors.Where(x => x.Email == ccaVm.CounselorEmail).Select(x => x.ID).FirstOrDefaultAsync().ConfigureAwait(false);
                    }

                    if (counselorId != 0)
                    {
                        cca.CounselorID = counselorId;
                    }
                    else // Create a counselor entry in the table.
                    {

                        var counselor = new Counselor()
                        {
                            Email = ccaVm.CounselorEmail,
                            FirstName = ccaVm.CounselorFirstName,
                            LastName = ccaVm.CounselorLastName,
                            Phone = ccaVm.CounselorPhoneNumber
                        };

                        // Find school name for display purposes 

                        if (cca.EnrollmentLocationID != GlobalVariables.PRIVATESCHOOLID)
                        {
                            counselor.EnrollmentLocationID = cca.EnrollmentLocationID;
                            counselor.EnrollmentLocationSchoolNameID = student.EnrollmentLocationSchoolNamesID;
                            var school = await cactus.CactusSchools.FirstOrDefaultAsync(m => m.ID == student.EnrollmentLocationSchoolNamesID).ConfigureAwait(false);

                            counselor.School = school.Name;

                        }
                        else
                        {
                            counselor.School = student.SchoolOfRecord;
                        }

                        db.Counselors.Add(counselor);

                        await db.SaveChangesAsync().ConfigureAwait(false);

                        // Lookup counselor in updated table to assign new ID to CCA
                        cca.CounselorID = await db.Counselors.Where(m => m.Email == ccaVm.CounselorEmail).Select(m => m.ID).FirstOrDefaultAsync().ConfigureAwait(false);
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 4
0
        // GET: CCAs/Create
        /// <summary>
        /// Set up lists and viewmodel for creation of student CCA
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> Create()
        {
            try
            {
                var userId = User.Identity.GetUserId();
                var model = new CCAViewModel();
                var leaId = await db.Students.Where(m => m.UserId == userId).Select(m => m.EnrollmentLocationID).FirstOrDefaultAsync().ConfigureAwait(false);
                model.EnrollmentLocationID = (int)leaId;
                model.UserId = userId;
                model = GetSelectLists(model);

                return View(model);
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Error getting Select List information! Error: " + ex.Message;
                return View("Error");
            }
        }