Exemplo n.º 1
0
        public ActionResult Edit(Grade gradeEdit, int id = 0)
        {
            var grade       = gradeRepository.FindById(id);
            var studentList = from student in studentRepository.List select student;
            var bookList    = from book in bookRespository.List select book;
            var chapterList = from chapter in chapterRepository.List select chapter;

            if (ModelState.IsValid)
            {
                grade.Student_ID    = gradeEdit.Student_ID;
                grade.Book_ID       = gradeEdit.Book_ID;
                grade.Chapter_ID    = gradeEdit.Chapter_ID;
                grade.Homework      = gradeEdit.Homework;
                grade.Excercise     = gradeEdit.Excercise;
                grade.Participation = gradeEdit.Participation;
                grade.CreateDate    = DateTime.Now;

                gradeRepository.Update(grade);

                return(Json(new { success = true }));
            }

            ViewBag.Student_ID = new SelectList(studentList, "StudentId", "Name", grade.Student_ID);
            ViewBag.Book_ID    = new SelectList(bookList, "BookId", "Book_Name", grade.Book_ID);
            ViewBag.Chapter_ID = new SelectList(chapterList, "ChapterID", "ChapterDescription");

            return(PartialView("_Edit", grade));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Number,Symbol")] Grade grade)
        {
            if (id != grade.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    gradeRepository.Update(grade);
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GradeExists(grade.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(grade));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit([FromBody] Grade grade)
        {
            var user = await gradeRepository.Get(grade.Id);

            if (user == null)
            {
                return(NotFound(new { status = ResultStatus.STATUS_NOT_FOUND, message = "Không tìm thấy nghề nghiệp" }));
            }

            if (String.IsNullOrEmpty(grade.Name))
            {
                return(Ok(new { status = ResultStatus.STATUS_INVALID_INPUT, message = "Tên khối không được để trống" }));
            }


            user.Name = grade.Name;
            await gradeRepository.Update(grade.Id, grade);

            return(Ok(new { status = ResultStatus.STATUS_OK, message = "Sửa thông tin khối thanh cong", data = grade }));
        }
Exemplo n.º 4
0
        public void UpdateGrade()
        {
            //create the student
            var newStudent = new Student()
            {
                FirstName = "Mikesh",
                LastName  = "Mistry"
            };


            //add the student
            studentRepository.Add(newStudent);

            //Find the student
            var foundStudent = studentRepository.GetAll().ToList();

            //create a course
            var newCourse = new Course()
            {
                Name        = "Introduction To C# Programming",
                Description = "Introduction To C# Programming"
            };

            //add the course to the database
            courseRepository.Add(newCourse);

            //find the course
            var foundCourse = courseRepository.GetAll().ToList();


            //create a new grade
            var newGrade = new Grade()
            {
                Student     = newStudent,
                Course      = newCourse,
                LetterGrade = "A+"
            };

            //add the grade
            gradeRepository.Add(newGrade);



            //find the grade
            var foundGrade = gradeRepository.Find(grade => grade.Student.StudentId == foundStudent[0].StudentId &&
                                                  grade.Course.CourseId == foundCourse[0].CourseId

                                                  ).FirstOrDefault();

            //test to see if we found the grade
            Assert.IsNotNull(foundGrade);

            //check are all the values the same
            Assert.AreEqual(foundGrade.Course.CourseId, foundCourse[0].CourseId);
            Assert.AreEqual(foundGrade.Student.StudentId, foundStudent[0].StudentId);
            Assert.AreEqual(foundGrade.LetterGrade, newGrade.LetterGrade);

            //now update the grade
            foundGrade.LetterGrade = "D+";
            gradeRepository.Update(foundGrade);

            //find the updated
            foundGrade = gradeRepository.Find(grade => grade.Student.StudentId == foundStudent[0].StudentId &&
                                              grade.Course.CourseId == foundCourse[0].CourseId

                                              ).FirstOrDefault();
            //test to see if we found the grade
            Assert.IsNotNull(foundGrade);

            //check are all the values the same
            Assert.AreEqual(foundGrade.Course.CourseId, foundCourse[0].CourseId);
            Assert.AreEqual(foundGrade.Student.StudentId, foundStudent[0].StudentId);
            Assert.AreEqual(foundGrade.LetterGrade, newGrade.LetterGrade);
        }
Exemplo n.º 5
0
        // ReSharper disable once UnusedMember.Global
        public void Post(GradeUpsertRequest request)
        {
            Guard.IsTrue(lessonId => 0 < lessonId, request.LessonId);
            Guard.AgainstEmpty(request.Provider);
            Guard.AgainstEmpty(request.ProviderId);
            var existingUser = UserHelpers.GetExistingUser(request, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingUser);

            Guard.AgainstEmpty(request.StudentProvider);
            Guard.AgainstEmpty(request.StudentProviderId);
            var existingStudent = UserHelpers.GetExistingUser(new LessonDeleteRequest {
                Provider = request.StudentProvider, ProviderId = request.StudentProviderId
            }, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingStudent);
            Guard.IsTrue(es => es.IsStudent, existingStudent);

            var lesson = LessonRepository.Find(request.LessonId);

            if (lesson == null || lesson.IsDeleted)
            {
                throw new HttpError(HttpStatusCode.NotFound, "NotFound");
            }

            if (request.Provider != lesson.Provider || request.ProviderId != lesson.ProviderId)
            {
                throw new HttpError(HttpStatusCode.Unauthorized, "Unauthorized");
            }

            var grade = GradeRepository.GetGrade(request.LessonId, request.StudentProvider, request.ProviderId);

            if (grade == null)
            {
                grade = new GradeModel
                {
                    LessonId          = request.LessonId,
                    StudentProvider   = request.StudentProvider,
                    StudentProviderId = request.StudentProviderId,
                    TeacherProvider   = request.Provider,
                    TeacherProviderId = request.ProviderId,
                    Grade             = request.Grade,
                    Comments          = request.Comments
                };

                GradeRepository.Add(grade);
            }
            else
            {
                grade.LessonId          = request.LessonId;
                grade.StudentProvider   = request.StudentProvider;
                grade.StudentProviderId = request.StudentProviderId;
                grade.TeacherProvider   = request.Provider;
                grade.TeacherProviderId = request.ProviderId;
                grade.Grade             = request.Grade;
                grade.Comments          = request.Comments;
                grade.UpdateDateUtc     = DateTime.UtcNow;

                GradeRepository.Update(grade);
            }
        }