コード例 #1
0
        public void AddNote_InvalidStudent_ShouldReturnDefaultView()
        {
            AddNoteBm bind = new AddNoteBm()
            {
                Content = "Hi"
            };

            _controller.WithCallTo(c => c.AddNote(bind, 2)).ShouldRenderDefaultView();
        }
コード例 #2
0
        public void AddNote_ShouldRedirectToStudentNotes()
        {
            AddNoteBm bind = new AddNoteBm()
            {
                Content = "Hi"
            };

            _controller.WithCallTo(c => c.AddNote(bind, 1))
            .ShouldRedirectTo <StudentsController>(typeof(StudentsController).GetMethod("StudentNotes"));
        }
コード例 #3
0
        public ActionResult AddNote(AddNoteBm bind, int id)
        {
            if (this.ModelState.IsValid)
            {
                this.service.AddNote(bind, id);
                return(RedirectToAction("StudentNotes", "SchoolDiary"));
            }

            return(this.View());
        }
コード例 #4
0
        public void AddNote_ShouldAddNote()
        {
            AddNoteBm bind = new AddNoteBm()
            {
                Content = "Hi"
            };

            _service.AddNote(bind, 1);

            Assert.AreEqual(1, _context.Notes.Count());
            Assert.AreEqual("Hi", _context.Notes.First().Content);
        }
コード例 #5
0
        public ActionResult AddNote(AddNoteBm bind, int id)
        {
            if (!this.service.IsStudentExists(id))
            {
                this.ModelState.AddModelError("Student", "Ученикът трябва да фигурира в системата.");
            }

            if (this.ModelState.IsValid)
            {
                this.service.AddNote(bind, id);
                return(this.RedirectToAction("StudentNotes", "Students"));
            }

            return(this.View());
        }
コード例 #6
0
ファイル: TeacherService.cs プロジェクト: T316/SchoolSystem
        public void AddNote(AddNoteBm bind, int id)
        {
            Note note = new Note();

            note.Content = bind.Content;
            note.Date    = DateTime.Now;

            string  username = bind.TeacherName;
            Teacher teacher  = this.Context.Teachers.FirstOrDefault(t => t.User.UserName == username);

            note.Teacher = teacher;

            Student student = this.Context.Students.FirstOrDefault(s => s.Id == id);

            note.Student = student;

            this.Context.Notes.Add(note);
            this.Context.SaveChanges();
        }