Example #1
0
        public async Task<ActionResult> UsoeEdit(UsoeCcaViewModel ccaVm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    CCA cca = await db.CCAs.FindAsync(ccaVm.CcaID).ConfigureAwait(false);

                    Mapper.CreateMap<UsoeCcaViewModel, CCA>().ForAllMembers(opt => opt.Condition(srs => !srs.IsSourceValueNull));

                    cca = Mapper.Map<UsoeCcaViewModel, CCA>(ccaVm, cca);

                    // Pull out the Fiscal year from the session (i.e. Winter (2015-2016) we will put out 2016

                    var session = await db.Session.FindAsync(cca.SessionID).ConfigureAwait(false);
                    cca.FiscalYear = GetFiscalYear(session.Name);

                    //db.Entry(cca).State = EntityState.Modified;

                    await db.SaveChangesAsync().ConfigureAwait(false);
                    return RedirectToAction("CcaInterface", "Admin");
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Error processing CCA save! Error: " + ex.Message;
                    return View("Error");
                }
            }

            //Capture errors from Modelstate and return to user.

            var errors = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList();
            foreach (var error in errors)
                ModelState.AddModelError("", error.Select(x => x.ErrorMessage).First());

            await SetUpUsoeEditViewModel(ccaVm).ConfigureAwait(false);

            return View(ccaVm);
        }
Example #2
0
        private async Task SetUpUsoeEditViewModel(UsoeCcaViewModel ccaVm)
        {

            try
            {
                var status = new SelectList(await db.CourseCompletionStatus.ToListAsync().ConfigureAwait(false), "ID", "Status", ccaVm.CourseCompletionStatusID);
                ViewBag.CourseCompletionStatusID = status;

                ccaVm.CourseCreditList = await GetCourseCredit(ccaVm.OnlineCourse.Credit);

                var leaId = ccaVm.Student.EnrollmentLocationID;
                var schoolId = ccaVm.Student.EnrollmentLocationSchoolNamesID;

                switch (leaId)
                {
                    case GlobalVariables.HOMESCHOOLID:
                        ViewBag.Lea = "HOMESCHOOL";
                        ViewBag.School = "HOMESCHOOL";
                        break;
                    case GlobalVariables.PRIVATESCHOOLID:
                        ViewBag.Lea = "PRIVATESCHOOL";
                        ViewBag.School = ccaVm.Student.SchoolOfRecord;
                        break;
                    default:
                        if (leaId != null)
                            ViewBag.Lea = await cactus.CactusInstitutions.Where(c => c.ID == leaId).Select(m => m.Name).FirstOrDefaultAsync().ConfigureAwait(false);
                        else
                            ViewBag.Lea = "UNKNOWN";

                        if (schoolId != null)
                            ViewBag.School = await cactus.CactusSchools.Where(c => c.ID == schoolId).Select(m => m.Name).FirstOrDefaultAsync().ConfigureAwait(false);
                        else
                            ViewBag.School = "UNKNOWN";
                        break;
                }

                //if (leaId == 1) // HomeSchool
                //{
                //    ViewBag.Lea = "HOMESCHOOL";
                //    ViewBag.School = "HOMESCHOOL";
                //}
                //else if (leaId == 2) //PrivateSchool
                //{
                //    ViewBag.Lea = "PRIVATESCHOOL";
                //    ViewBag.School = ccaVm.Student.SchoolOfRecord;
                //}
                //else
                //{
                //    ViewBag.Lea = await cactus.CactusInstitutions.Where(c => c.ID == leaId).Select(m => m.Name).FirstOrDefaultAsync().ConfigureAwait(false);

                //    if (schoolId != null)
                //        ViewBag.School = await cactus.CactusSchools.Where(c => c.ID == schoolId).Select(m => m.Name).FirstOrDefaultAsync().ConfigureAwait(false);
                //    else
                //        ViewBag.School = "UNKNOWN";
                //}

            }
            catch
            {
                throw;
            }
        }