Exemple #1
0
        public async Task <IActionResult> AddMark(int studentId, int markId)
        {
            var user = await GetCurrentUserAsync();

            if (user is TeacherAccount teacher)
            {
                var student = _students.GetById(studentId);
                if (markId > 0)
                {
                    var mark = _marks.GetById(markId);

                    var model = new AddMarkModel()
                    {
                        Student    = student,
                        MarkToEdit = mark
                    };
                    return(View(model));
                }
                else
                {
                    var model = new AddMarkModel()
                    {
                        Student = student
                    };
                    return(View(model));
                }
            }

            return(RedirectToAction("Error", "Home"));
        }
Exemple #2
0
        public ActionResult AddMark(AddMarkModel model)
        {
            Course _course  = db.Courses.Find(int.Parse(model.returnUrl.Split('=')[1]));
            var    students = _course.Students;

            foreach (var item in students)
            {
                db.Marks.Add(new Mark()
                {
                    Description = model.Description, CourseId = _course.Id, Date = model.Date,
                    StudentId   = item.Id
                });
            }
            db.SaveChanges();
            return(Redirect(model.returnUrl));
        }
Exemple #3
0
        public async Task <IActionResult> AddMarkSubmit(AddMarkModel model, int studentId, int markId)
        {
            if (ModelState.IsValid && model.MarkValue > 0)
            {
                var user = await GetCurrentUserAsync();

                if (user is TeacherAccount teacherAccount)
                {
                    var mark = new Mark()
                    {
                        Teacher     = teacherAccount,
                        MarkType    = (MarkType)model.MarkValue,
                        Description = model.Description,
                        MarkDate    = DateTime.Now
                    };

                    if (markId == 0)
                    {
                        _students.AddNewMark(studentId, mark);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        _marks.EditMark(markId, mark);
                        var markNew = _marks.GetById(markId);

                        if (markNew.Assignment != null)
                        {
                            var assignmentId = markNew.Assignment.Id;
                            var marks        = _marks.GetForAssignmentId(assignmentId);
                            var total        = 0;
                            foreach (var m in marks)
                            {
                                total += (int)m.MarkType;
                            }

                            _assignments.SetGraded(markNew.Assignment, total / marks.Count);
                        }

                        return(RedirectToAction("Index"));
                    }
                }
            }

            return(RedirectToAction("Error", "Home"));
        }