public List <MarksViewModel> GetListForMarksTable(int studentId, int examId) { var activeYear = _db.AcademicYears.FirstOrDefault(x => x.IsCurrent); if (activeYear == null) { return(new List <MarksViewModel>()); } var classSecId = _db.StudentClassSections.First(x => x.StudentId == studentId).ClassSectionId; var marksList = _db.Marks.Where(x => x.ExamId == examId && x.StudentId == studentId && x.YearId == activeYear.YearId).ToList(); var classSectionSubjectsList = _db.ClassSectionSubjects.Where(x => x.ClassSectionId == classSecId).ToList(); var subjectIdList = classSectionSubjectsList.Select(x => x.SubjectId).ToList(); var subjectList = _db.Subjects.Where(x => subjectIdList.Contains(x.SubjectId)).ToList(); List <MarksViewModel> marksModelList = new List <MarksViewModel>(); foreach (var classSectionSubject in classSectionSubjectsList) { var marks = marksList.FirstOrDefault(x => x.ClassSectionSubjectId == classSectionSubject.Id); var subject = subjectList.First(x => x.SubjectId == classSectionSubject.SubjectId); MarksViewModel markModel = new MarksViewModel { SubjectId = subject.SubjectId, Subject = subject.SubjectName, StudentId = studentId, ClassSectionSubjectId = classSectionSubject.Id, Marks = marks != null ? marks.Marks : 0, MarksId = marks != null ? marks.MarksId : -1, ExamId = examId }; marksModelList.Add(markModel); } return(marksModelList); }
// GET: Marks public IActionResult Index(int page = 1) { PageViewModel pageViewModel = new PageViewModel(teacherDAO.Count(), page, 10); MarksViewModel model = new MarksViewModel(markDAO.GetList(page), pageViewModel); return(View(model)); }
public IActionResult DashBoard() { var userListProfile = new UserProfileListViewModel(); var person = new UserProfileViewModel(); long currentId = Convert.ToInt32(_signInManager.UserManager.GetUserId(User)); var currentUserDto = _userService.GetUserById(currentId); person.PersonalData = _mapper.Map <UserDetailedViewModel>(currentUserDto); var modulesDto = _moduleService.GetModules(); var modules = _mapper.Map <IList <ModuleViewModel> >(modulesDto); var themesDto = _themeService.GetThemes(); var themes = _mapper.Map <IList <ThemeViewModel> >(themesDto); person.Modules = modules; person.Themes = themes; var marks = new MarksViewModel(); if (User.IsInRole("Intern")) { var themeMarksDto = _themeMarkService.GetThemeMarksByUserId(currentId); marks.ThemeMarks = _mapper.Map <IList <ThemeMarkViewModel> >(themeMarksDto); var examMarksDto = _examMarkService.GetExamMarksByUserId(currentId); marks.ExamMarks = _mapper.Map <IList <ExamMarkViewModel> >(examMarksDto); person.Marks = marks; userListProfile.UserProfile = person; return(View("../DashBoard/Index", userListProfile)); } else if (User.IsInRole("Menthor") || User.IsInRole("Admin")) { var themeMarksDto = _themeMarkService.GetThemeMarks(); marks.ThemeMarks = _mapper.Map <IList <ThemeMarkViewModel> >(themeMarksDto); var examMarksDto = _examMarkService.GetExamMarks(); marks.ExamMarks = _mapper.Map <IList <ExamMarkViewModel> >(examMarksDto); person.Marks = marks; if (User.IsInRole("Admin")) { var usersDto = _userService.GetUsersDetails(); userListProfile.UserProfile = person; userListProfile.Users = _mapper.Map <IList <UserDetailedViewModel> >(usersDto); return(View("../DashBoard/Index", userListProfile)); } userListProfile.UserProfile = person; return(View("../DashBoard/Index", userListProfile)); } return(View("Error")); }
public IActionResult GetMarks(long moduleId) { var currentId = Convert.ToInt32(_signInManager.UserManager.GetUserId(User)); var thememarks = GetThemeMarks(moduleId, currentId); var examMarksDto = _examMarkService.GetExamMarksByUserId(currentId); var marks = new MarksViewModel(); marks.ThemeMarks = thememarks; marks.ExamMarks = _mapper.Map <IList <ExamMarkViewModel> >(examMarksDto); return(Json(marks)); }
public IHttpActionResult Put(MarksViewModel mks) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new EMSEntities()) { try { var existingMarks = ctx.MARKSMSTs.Where(s => s.TRNNO == mks.TRNNO) .FirstOrDefault <MARKSMST>(); if (existingMarks != null) { existingMarks.CLASS_TRNNO = mks.CLASS_TRNNO; existingMarks.EM_TRNNO = mks.EM_TRNNO; ctx.SaveChanges(); } else { return(NotFound()); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } return(Ok()); }
public IHttpActionResult GetMarksById(int id) { MarksViewModel mkss = null; using (var ctx = new EMSEntities()) { mkss = ctx.MARKSMSTs .Where(s => s.TRNNO == id) .Select(s => new MarksViewModel() { TRNNO = s.TRNNO, CLASS_TRNNO = s.CLASS_TRNNO, EM_TRNNO = s.EM_TRNNO }).FirstOrDefault <MarksViewModel>(); } if (mkss == null) { return(NotFound()); } return(Ok(mkss)); }
public DashboardNavigator(AttendanceViewModel attendanceViewModel, MarksViewModel marksViewModel) { this.ConfigureNewViewModel("Attendance", ViewModelEnum.Attendance, attendanceViewModel); this.ConfigureNewViewModel("Marks", ViewModelEnum.Marks, marksViewModel); }
public Marks() { InitializeComponent(); viewModel = new MarksViewModel(); this.DataContext = viewModel; }
public IHttpActionResult PostNewMarks(MarksViewModel mks) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (var ctx = new EMSEntities()) { int _trnno; int _sr1 = 1; int _sr = 1; //int _oldTrnno = 0; var _oldTrnno = ctx.MARKSMSTs.Where(s => s.MDT == mks.MDT && s.EXAM_TRNNO == mks.EXAM_TRNNO && s.CLASS_TRNNO == mks.CLASS_TRNNO && s.GRPMST_TRNNO == mks.GRPMST_TRNNO && s.EM_TRNNO == mks.EM_TRNNO).FirstOrDefault(); if (_oldTrnno != null) { _trnno = Convert.ToInt32(_oldTrnno.TRNNO); } else { _trnno = Convert.ToInt32(ctx.MARKSMSTs.OrderByDescending(t => t.TRNNO).FirstOrDefault().TRNNO); _trnno = _trnno + 1; } mks.TRNNO = _trnno; ctx.MARKSMSTs.Add(new MARKSMST() { TRNNO = mks.TRNNO, MDT = mks.MDT, EXAM_TRNNO = mks.EXAM_TRNNO, CLASS_TRNNO = mks.CLASS_TRNNO, GRPMST_TRNNO = mks.GRPMST_TRNNO, EM_TRNNO = mks.EM_TRNNO, }); foreach (var dtls in mks.MARKSDTLs) { var markdetail = new MARKSDTL { TRNNO = _trnno, SR = _sr, EM_TRNNO = dtls.EM_TRNNO }; ctx.MARKSDTLs.Add(markdetail); foreach (var dt1 in dtls.MARKSDTL1) { var markdtl1 = new MARKSDTL1 { TRNNO = _trnno, SR = _sr, SR1 = dt1.SR1, GMARKS = dt1.GMARKS, MARKTOTALDTL_TRNNO = dt1.MARKTOTALDTL_TRNNO, MARKTOTALDTL_SR = dt1.MARKTOTALDTL_SR }; ctx.MARKSDTL1.Add(markdtl1); _sr1++; } _sr++; } try { ctx.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } return(Ok()); }