public ActionResult AddClass(AddClassViewModel model) { try { if (!ModelState.IsValid) { return(View()); } HttpCookie conString = Request.Cookies.Get("rwxgqlb"); Class c = null; try { c = new Class(model.Name, model.RollNo, model.TeacherId, Cryptography.Decrypt(conString.Value)); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } ViewClassDetailsViewModel vcdvm = new ViewClassDetailsViewModel(); if (c != null) { vcdvm = new ViewClassDetailsViewModel { Id = c.ClassId, Incharge = c.Incharge.Name, Name = c.Name, RollNo = c.RollNoIndex, Sections = new List <ClassSection>(), Strength = c.Strength, Subjects = new List <ClassSubject>() }; foreach (var item in c.GetSections()) { vcdvm.Sections.Add(new ClassSection { Id = item.SectionId, Name = item.Name, Strength = item.Strength }); } foreach (var item in c.GetSubjects()) { vcdvm.Subjects.Add(new ClassSubject { Id = item.SubjectId, Name = item.Name }); } } ViewBag.Success = true; return(View("ViewClassDetails", vcdvm)); } catch (Exception ex) { return(Content(ex.Message)); } }
/// <summary> /// Action to View Details of a certain class /// </summary> /// <param name="id">class id</param> /// <param name="s">success flag</param> /// <param name="err">error flag</param> /// <returns></returns> public ActionResult ViewClassDetails(int id, bool s = false, bool err = false) { try { ViewBag.Success = s; ViewBag.Error = err; int absentToday = 0, presentToday = 0; HttpCookie conString = Request.Cookies.Get("rwxgqlb"); Class c = new Class(id, Cryptography.Decrypt(conString.Value)); ViewClassDetailsViewModel vcdvm = new ViewClassDetailsViewModel { Id = c.ClassId, Incharge = c.Incharge.Name, Name = c.Name, RollNo = c.RollNoIndex, Sections = new List <ClassSection>(), Strength = c.Strength, Subjects = new List <ClassSubject>(), Progress = new List <SectionMonthlyProgress>() }; foreach (var item in c.GetSections()) { vcdvm.Sections.Add(new ClassSection { Id = item.SectionId, Name = item.Name, Strength = item.Strength }); absentToday += item.GetAbsentStudents(DateTime.Now); presentToday += item.GetPresentStudents(DateTime.Now); } foreach (var item in c.GetSubjects()) { vcdvm.Subjects.Add(new ClassSubject { Id = item.SubjectId, Name = item.Name }); } for (int i = 1; i <= 12; i++) { Random ran = new Random(); Month month = new Month { Number = i, Year = DateTime.Now.Year }; List <SectionProgress> lstSecProgress = new List <SectionProgress>(); foreach (var item in c.GetSections()) { lstSecProgress.Add(new SectionProgress { ProgressPercent = item.GetMonthlyProgress(month).Result, SectionName = item.Name }); } vcdvm.Progress.Add(new SectionMonthlyProgress { Month = month.Number, SectionsProgres = lstSecProgress }); } return(View(vcdvm)); } catch (Exception ex) { return(Content(ex.Message)); } }