public ActionResult AddGrade([Bind(Include = "StudentsGroupAddGradeViewModels")] StudentsGroupAddGradeViewModelList model) { foreach (var studentsGroupAddGradeViewModels in model.StudentsGroupAddGradeViewModels) { if (studentsGroupAddGradeViewModels.Note != null) { var grade = new Grade() { Value = studentsGroupAddGradeViewModels.Grade.Value, Owner = studentsGroupAddGradeViewModels.MyUserId, Note = studentsGroupAddGradeViewModels.Note, Date = DateTime.Now, SubjectId = studentsGroupAddGradeViewModels.SubjectId, Weight = studentsGroupAddGradeViewModels.Weight.Value }; db.Grades.Add(grade); } } db.SaveChanges(); if (!model.StudentsGroupAddGradeViewModels.Any()) { return(View("~\\Views\\Grades\\index.cshtml")); } return(RedirectToAction("Index", "Grades", new { id = 1 })); }
public ActionResult AddGrade(int?studentGroupId, int?subjectId) { if (User.IsInRole("Teacher")) { var studentsGroup = db.StudentsGroups.FirstOrDefault(x => x.Id == studentGroupId); var subjectName = db.Subjects.FirstOrDefault(x => x.Id == subjectId).Name; var myUsers = db.MyUsers.Where(x => x.StudentsGroupId == studentGroupId).Select(x => new StudentsGroupAddGradeViewModel() { MyUserId = x.Owner, MyUser = x, SubjectName = subjectName, StudentGroupName = studentsGroup.Level + studentsGroup.Name, SubjectId = (int)subjectId, StudentsGroupId = (int)studentGroupId }).ToList(); StudentsGroupAddGradeViewModelList model = new StudentsGroupAddGradeViewModelList(); model.StudentsGroupAddGradeViewModels = myUsers; return(View("~\\Views\\StudentsGroups\\AddGradeTeacher.cshtml", model)); } return(HttpNotFound()); }