示例#1
0
        public EditMarkVm GetMarkForEdit(int id)
        {
            Mark       mark = this.Context.Marks.FirstOrDefault(m => m.Id == id);
            EditMarkVm vm   = new EditMarkVm();

            vm.Id          = id;
            vm.Value       = mark.Value;
            vm.SubjectName = mark.Subject.Name;
            vm.StudentId   = mark.Student.Id;

            return(vm);
        }
示例#2
0
        public void EditMark(EditMarkVm vm, int id)
        {
            Mark    mark    = this.Context.Marks.FirstOrDefault(m => m.Id == id);
            Student student = this.Context.Students.FirstOrDefault(s => s.Id == vm.StudentId);
            Subject subject = this.Context.Subjects.FirstOrDefault(s => s.Name == vm.SubjectName);

            mark.Id      = vm.Id;
            mark.Subject = subject;
            mark.Value   = vm.Value;
            mark.Student = student;

            this.Context.Entry(mark).State = EntityState.Modified;
            this.Context.SaveChanges();
        }
示例#3
0
        public bool IsSubjectNameExists(EditMarkVm vm)
        {
            if (vm.SubjectName == null)
            {
                return(true);
            }

            Subject subject = this.Context.Subjects.FirstOrDefault(s => s.Name == vm.SubjectName);

            if (subject == null)
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        public ActionResult EditMark(EditMarkVm vm, int id)
        {
            if (!this.service.IsSubjectNameExists(vm))
            {
                this.ModelState.AddModelError("SubjectName", "Subject must exist in School diary");
            }

            if (!this.service.IsStudentExists(vm.StudentId))
            {
                this.ModelState.AddModelError("Student", "Student must exist in School diary");
            }

            if (this.ModelState.IsValid)
            {
                this.service.EditMark(vm, id);
                return(RedirectToAction("StudentMarks", "SchoolDiary", new { id = vm.StudentId }));
            }

            return(this.View(vm));
        }
示例#5
0
        public ActionResult EditMark(int id)
        {
            EditMarkVm vm = this.service.GetMarkForEdit(id);

            return(this.View(vm));
        }