public IActionResult Get(int Id) { ViewBag.Teachers = Map(teacherService.GetAll().ToList()); ViewBag.Teacher = Map(teacherService.GetById(Id)); List <TeacherGradeViewModel> TGList = Map(tgService.GetAll().Where(x => x.TeacherId == Id).ToList()); List <GradeViewModel> GradeList = new List <GradeViewModel>(); foreach (var item in TGList) { GradeViewModel grade = Map(gradeService.GetById(item.GradeId)); grade.Pupils = Map(pupilService.GetAll().Where(x => x.GradePropId == item.GradeId).ToList()); GradeList.Add(grade); } return(View("Index", GradeList)); }
public IActionResult Delete(int?id) { if (id == null) { return(NotFound()); } GradeViewModel gradeViewModel = _classroomService.GetGradeById(id.Value); if (gradeViewModel == null) { return(NotFound()); } return(View(gradeViewModel)); }
public IActionResult Get(int?Id) { if (Id != null) { ViewBag.PupilsInClass = Map(pupilService.GetAll().Where(x => x.GradePropId == Id)); ViewBag.PupilFree = Map(pupilService.GetAll().Where(x => x.GradePropId == null)).OrderBy(x => x.Age).ThenBy(x => x.Surname); GradeViewModel grade = Map(gradeService.GetById(Id.Value)); ViewBag.TG = Map(tgService.GetAll().Where(x => x.GradeId == Id)); ViewBag.Teachers = Map(teacherService.GetAll(), Id.Value); ViewBag.TList = Map(teacherService.GetAll()); return(View("Details", grade)); } return(NotFound()); }
public async Task <IActionResult> PostAsync([FromBody] GradeViewModel gradeDetail) { if (gradeDetail == null) { return(this.BadRequest("Error while saving grade details to storage.")); } this.RecordEvent("Grade - HTTP Post call to add grade details.", RequestType.Initiated); this.logger.LogInformation("Call to add grade details."); if (gradeDetail == null) { this.logger.LogInformation("Error while saving grade details to storage."); this.RecordEvent("Grade - HTTP Post call to add grade details.", RequestType.Failed); return(this.BadRequest("Error while saving grade details to storage.")); } try { var grades = await this.unitOfWork.GradeRepository.FindAsync(grade => grade.GradeName == gradeDetail.GradeName); if (grades.Any()) { this.logger.LogInformation($"Grade title already exists with gradeName :{gradeDetail.GradeName}"); this.RecordEvent("Grade - HTTP Post call to add grade details.", RequestType.Failed); return(this.StatusCode(StatusCodes.Status409Conflict)); } var gradeEntityModel = this.gradeMapper.MapToDTO( gradeDetail, this.UserObjectId); this.unitOfWork.GradeRepository.Add(gradeEntityModel); await this.unitOfWork.SaveChangesAsync(); this.RecordEvent("Grade - HTTP Post call succeeded.", RequestType.Succeeded); return(this.Ok(gradeEntityModel)); } catch (Exception ex) { this.RecordEvent("Grade - HTTP Post call failed for saving grade data", RequestType.Failed); this.logger.LogError(ex, $"Error while saving grade details"); throw; } }
public ActionResult Visualizza(int id = 1) { var repo = new StudentGradeRepository(); //var gradeList = repo.GetStudentGrades(id); var gradeList = repo.GetStudentGradesExt(id); var gradeVM = new GradeViewModel(); gradeVM.StudentId = id; gradeVM.ListaVoti = new List <GradeDtoVM>(); foreach (var grade in gradeList) { var dto = MySingleton.GetAutoMapperInstance().Map <GradeDtoVM>(grade); gradeVM.ListaVoti.Add(dto); } return(View(gradeVM)); }
public IActionResult Details(int?id) { if (id == null) { return(NotFound()); } GradeViewModel gradeViewModel = _classroomService.GetGradeById(id.Value); if (gradeViewModel == null) { return(NotFound()); } gradeViewModel.Student = _classroomService.GetStudentById(gradeViewModel.StudentId); return(View(gradeViewModel)); }
public async Task GradeStudentShouldReturnTrueIfValidModel() { var controller = this.SetupControllerForAuthenticationConnectTests(); var model = new GradeViewModel() { StudentId = 1 }; var result = await controller.GradeStudent(model); Assert.IsInstanceOfType(result, typeof(JsonResult)); var jsonResult = (JsonResult)result; var str = jsonResult.Value.ToString(); Assert.IsTrue(jsonResult.Value.ToString() == "{ status = true, studentId = 1 }"); }
public IHttpActionResult UpdateGrade([FromBody] GradeViewModel value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _studentData.UpdateGrade(value); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
// GET: Assess the student // Made by: Muhammed Yasin Yildirim public ActionResult Assess() { string userId = User.Identity.GetUserId <string>(); var professor = _context.Professors.FirstOrDefault(p => p.Id == userId); if (professor == null) { return(HttpNotFound()); } var viewModel = new GradeViewModel() { ProfessorCourses = professor.Courses.ToList() }; return(View(viewModel)); }
public void ConvertJsonToObservable() { //start with courses foreach (SchoolCourse course in currentCoursesJson) { SchoolCourseViewModel courseViewModel = new SchoolCourseViewModel(); courseViewModel.Id = course.Id; courseViewModel.Name = course.Name; courseViewModel.Start_at = course.Start_at; courseViewModel.End_at = course.End_at; currentCourses.Add(courseViewModel); } foreach (Assignment task in currentAssignmentsJson) { AssignmentViewModel taskViewModel = new AssignmentViewModel(); taskViewModel.Points_Possible = task.Points_Possible; taskViewModel.Name = task.Name; taskViewModel.Description = task.Description; taskViewModel.Due_at = task.Due_at; taskViewModel.Html_Url = task.Html_Url; taskViewModel.Course_Id = task.Course_id; currentAssignments.Add(taskViewModel); } //to get the grades I need to loop through current course AND enrollment if the ids match create a grade object foreach (SchoolCourse course in currentCoursesJson) { foreach (Enrollment enroll in currentEnrollmentsJson) { if (enroll.Course_Id == course.Id) { GradeViewModel currentGradeModel = new GradeViewModel(); currentGradeModel.Current_grade = enroll.Grade.Current_grade; currentGradeModel.Current_Score = enroll.Grade.Current_Score; currentGradeModel.ID = enroll.Course_Id; currentGrades.Add(currentGradeModel); } } } }
/// <summary> /// Update grade group. /// </summary> /// <param name="model">The grade information value.</param> /// <returns></returns> public ResultViewModel Edit(GradeViewModel model) { var result = new ResultViewModel(); using (TransactionScope scope = new TransactionScope()) { this.SetIsDefault(model); var gradeGroup = _unitOfWork.GetRepository <Grade>().GetCache(x => x.Id == model.Id).FirstOrDefault(); gradeGroup.Name = model.Name; gradeGroup.IsDefault = model.IsDefault; gradeGroup.LastModifyBy = _token.EmpNo; gradeGroup.LastModifyDate = DateTime.Now; _unitOfWork.GetRepository <Grade>().Update(gradeGroup); this.EditItem(gradeGroup.Id, model.GradeItems); _unitOfWork.Complete(scope); } this.ReloadCacheGrade(); return(result); }
/// <summary> /// Insert new grade group. /// </summary> /// <param name="model">The grade information value.</param> /// <returns></returns> public ResultViewModel Save(GradeViewModel model) { var result = new ResultViewModel(); using (TransactionScope scope = new TransactionScope()) { var gradeGroup = _mapper.Map <GradeViewModel, Grade>(model); this.SetIsDefault(model); gradeGroup.CreateBy = _token.EmpNo; gradeGroup.CreateDate = DateTime.Now; gradeGroup.CreateByPurchaseOrg = _token.PurchasingOrg[0]; _unitOfWork.GetRepository <Grade>().Add(gradeGroup); _unitOfWork.Complete(); this.SaveItem(gradeGroup.Id, model.GradeItems); _unitOfWork.Complete(scope); } this.ReloadCacheGrade(); return(result); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] GradeViewModel viewModel) { VerifyUser(); if (!ModelState.IsValid) { var exception = new { error = ResultFormatter.FormatErrorMessage(ModelState) }; return(new BadRequestObjectResult(exception)); } try { VerifyUser(); ValidateService.Validate(viewModel); await _service.Update(id, viewModel); return(NoContent()); } catch (ServiceValidationException ex) { var Result = new { error = ResultFormatter.Fail(ex), apiVersion = "1.0.0", statusCode = HttpStatusCode.BadRequest, message = "Data does not pass validation" }; return(new BadRequestObjectResult(Result)); } catch (Exception ex) { var error = new { statusCode = HttpStatusCode.InternalServerError, error = ex.Message }; return(StatusCode((int)HttpStatusCode.InternalServerError, error)); } }
public IActionResult Create(int?id) { if (id == null) { return(NotFound()); } GradeViewModel grade = new GradeViewModel(); grade.Student = _classroomService.GetStudentById(id.Value); grade.StudentId = grade.Student.StudentId; grade.Courses = _classroomService.ListFreeCoursesByStudent(id.Value); if (grade.Student == null) { return(NotFound()); } return(View(grade)); }
public void Should_Error_UploadValidate_EmptyData() { var repoMock = new Mock <IGradeRepository>(); repoMock.Setup(s => s.ReadAll()) .Returns(new List <GradeModel>().AsQueryable()); var service = GetService(GetServiceProvider(repoMock.Object).Object); var vm = new GradeViewModel(); var result = service.UploadValidate(new List <GradeViewModel>() { vm }); Assert.False(result.Item1); vm.Code = "test"; result = service.UploadValidate(new List <GradeViewModel>() { vm }); Assert.False(result.Item1); vm.Code = "0"; result = service.UploadValidate(new List <GradeViewModel>() { vm }); Assert.False(result.Item1); vm.Code = "110"; result = service.UploadValidate(new List <GradeViewModel>() { vm }); Assert.False(result.Item1); }
public ActionResult AutoGrade(GradeViewModel model) { int?QuizId = Convert.ToInt32(model.expected); if (QuizId != null) { Quiz quiz = db.Quiz.First(x => x.Id == QuizId); //Debug.WriteLine("your code: " + model.yourcode + "L: " + model.yourcode.Length); //Debug.WriteLine("Ouput: " + model.output.ToString().Trim()); //Debug.WriteLine("expected: " + quiz.ExpectedOutput.Trim()); //var newyourcode = model.yourcode.Trim().Replace(" ", ""); //Debug.WriteLine("your code trimmed: " + newyourcode + newyourcode.Length); //var replacequizexp = quiz.ExpectedInput.Trim().Replace(" ", ""); //Debug.WriteLine("the quiz expected: " + replacequizexp + "..." + replacequizexp.Length); //Debug.WriteLine(newyourcode.Equals(replacequizexp)); //Debug.WriteLine(model.output.Trim().Equals(quiz.ExpectedOutput)); try { string output = model.output.ToString().Trim(); //if (output.Equals(quiz.ExpectedOutput) && model.yourcode.Length.Equals(18)) //{ // ViewBag.Message = "Nice try, but you cannot simply print the proper output."; //} if (output.Equals(quiz.ExpectedOutput) && model.yourcode.Length > quiz.ExpectedOutput.Length + 10) { ViewBag.Message = "Well done!"; } else { ViewBag.Message = "Bummer! Something may be wrong with your input.\r\n" + quiz.ErrorMessage; } } catch (NullReferenceException e) { ViewBag.Message = e.Message + " It looks like the output of your code was empty."; } return(PartialView("_Grade")); } return(View()); }
public void LoadGrade(string studentName, GradeViewModel grade) { _studentName = studentName; _grade = grade; IsEnabled = (RightsEnum.Success == UserViewModel.CurrentUser.CanEdit(_grade)); if (CourseViewModel.HasSpecialGrade(grade.Subject)) { entSpecialGrade.Visibility = System.Windows.Visibility.Visible; staSpecialGrade.Visibility = System.Windows.Visibility.Visible; } Maintenance.LetterGrades.Keys.ToList().ForEach(g => cmbLetterGrade.Items.Add(g)); Maintenance.Comments.ToList().ForEach(g => cmbComment.Items.Add(g)); cmbComment.SelectedIndex = 0; staStudent.Content = studentName; staCourse.Content = _grade.Subject + " for " + _grade.MarkingPeriod + " " + _grade.Group + " with " + _grade.Teacher; cmbLetterGrade.Text = _grade.LetterGrade; entSpecialGrade.Text = _grade.SpecialGrade; var comment = _grade.Comment; foreach (var c in Maintenance.Comments) { var formattedComment = Maintenance.FormatCommentFromList(c); if (string.IsNullOrWhiteSpace(formattedComment)) { continue; } if (comment.StartsWith(formattedComment)) { cmbComment.Text = c; comment = comment.Substring(formattedComment.Length).Trim(); break; } } entComment.Text = comment; }
public IActionResult Create([Bind("StudentId,CourseId,Value")] GradeViewModel gradeViewModel) { try { if (ModelState.IsValid) { _classroomService.InsertGrade(gradeViewModel); return(RedirectToAction(nameof(List), new { id = gradeViewModel.StudentId })); } return(RedirectToAction(nameof(List), new { id = gradeViewModel.StudentId })); } catch (Exception ex) { gradeViewModel.Student = _classroomService.GetStudentById(gradeViewModel.StudentId); gradeViewModel.Courses = _classroomService.ListFreeCoursesByStudent(gradeViewModel.StudentId); return(View(gradeViewModel)); throw; } }
public IActionResult Index(string Surname, int?Age, string GradeName) { GradeViewModel grade = String.IsNullOrEmpty(GradeName) == false?Map(gradeService.GetAll().Where(x => x.Name == GradeName).FirstOrDefault()) : null; IEnumerable <PupilDTO> PupilDTO = pupilService.GetAll(); List <PupilViewModel> pupilList = new List <PupilViewModel>(); foreach (var pupil in PupilDTO) { bool ok = true; if (!String.IsNullOrEmpty(Surname)) { if (!pupil.Surname.ToLower().Contains(Surname.ToLower())) { ok = false; } } if (Age != null) { if (pupil.Age != Age) { ok = false; } } if (grade != null) { if (pupil.GradePropId != grade.Id) { ok = false; } } if (ok) { pupilList.Add(Map(pupil)); } } return(View("View", pupilList)); }
/// <summary> /// Validate information value in grade logic. /// </summary> /// <param name="model">The grade information value.</param> /// <returns></returns> public ResultViewModel ValidateData(GradeViewModel model) { var result = new ResultViewModel(); model.GradeItems = model.GradeItems.OrderBy(x => x.StartPoint).ToList(); int oldEnd = int.MinValue; foreach (var item in model.GradeItems) { if (item.StartPoint >= item.EndPoint) { result = UtilityService.InitialResultError(MessageValue.GradePointIncorrect, (int)HttpStatusCode.BadRequest); break; } if (oldEnd >= item.StartPoint) { result = UtilityService.InitialResultError(MessageValue.GradePointIncorrect, (int)HttpStatusCode.BadRequest); break; } oldEnd = item.EndPoint.Value; } return(result); }
public IActionResult Edit([FromBody] GradeViewModel model) { IActionResult response; if (_grade.IsUse(model.Id)) { response = BadRequest(UtilityService.InitialResultError(string.Format(MessageValue.IsUseMessageFormat, MessageValue.GradeMessage), (int)System.Net.HttpStatusCode.BadRequest)); } else { var validate = _grade.ValidateData(model); if (validate.IsError) { response = BadRequest(validate); } else { response = Ok(_grade.Edit(model)); } } return(response); }
public void Should_Exception_ValidationVM() { var repoMock = new Mock <IGradeRepository>(); var model = Model; model.Id = 1; repoMock.Setup(s => s.ReadAll()) .Returns(new List <GradeModel>() { model }.AsQueryable()); var serviceProvider = GetServiceProvider(repoMock.Object).Object; var service = GetService(serviceProvider); var vm = new GradeViewModel(); var validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Code = "str"; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Code = "0"; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Code = "1202"; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Type = Model.Type; vm.Code = Model.Code; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); }
public async Task <ActionResult> Create(GradeViewModel model) { if (ModelState.IsValid) { var myGrade = await Db.Grades.CountAsync(x => x.GradeName.Trim().Equals(model.GradeName.Trim()) && x.SchoolId.Equals(userSchool)); if (myGrade >= 1) { TempData["UserMessage"] = "Grade Already Exist in Database."; TempData["Title"] = "Error."; ViewBag.ClassName = new SelectList(Db.SchoolClasses.AsNoTracking(), "ClassCode", "ClassCode"); return(View(model)); } var grade = new Grade { GradeName = model.GradeName.Trim().ToUpper(), MinimumValue = model.MinimumValue, MaximumValue = model.MaximumValue, //GradePoint = model.GradePoint, Remark = model.Remark, SchoolId = userSchool //ClassName = item }; Db.Grades.Add(grade); await Db.SaveChangesAsync(); TempData["UserMessage"] = "Grade Added Successfully."; TempData["Title"] = "Success."; return(RedirectToAction("Index")); } //ViewBag.ClassName = new SelectList(Db.SchoolClasses.AsNoTracking(), "ClassCode", "ClassCode"); return(View(model)); }
public async Task PostAsync_DuplicateGradeName_ReturnsConflict() { // ARRANGE var gradeCollection = new List <Grade>(); var grade = new Grade { GradeName = "Grade A", Id = Guid.NewGuid(), }; var gradeModel = new GradeViewModel { GradeName = "Grade A", }; gradeCollection.Add(grade); this.unitOfWork.Setup(uow => uow.GradeRepository.FindAsync(It.IsAny <Expression <Func <Grade, bool> > >())).ReturnsAsync(gradeCollection); // ACT var result = (StatusCodeResult)await this.gradeController.PostAsync(gradeModel); // ASSERT Assert.AreEqual(result.StatusCode, StatusCodes.Status409Conflict); }
public async Task PatchAsync_RecordNotExists_ReturnsNotFound() { // ARRANGE var gradeCollection = new List <Grade>(); var grade = new Grade { GradeName = "Grade A", }; var gradeModel = new GradeViewModel { GradeName = "Grade A", Id = Guid.NewGuid(), }; this.unitOfWork.Setup(uow => uow.GradeRepository.FindAsync(It.IsAny <Expression <Func <Grade, bool> > >())).ReturnsAsync(gradeCollection); this.unitOfWork.Setup(uow => uow.GradeRepository.GetAsync(It.IsAny <Guid>())).ReturnsAsync(() => null); this.unitOfWork.Setup(uow => uow.GradeRepository.Update(It.IsAny <Grade>())).Returns(() => grade); // ACT var result = (ObjectResult)await this.gradeController.PatchAsync(gradeModel.Id, gradeModel); // ASSERT Assert.AreEqual(result.StatusCode, StatusCodes.Status404NotFound); }
public async Task <ActionResult> Score(GradeViewModel gradeViewModel) { var userId = User.Identity.GetUserId(); var tester = await _modelService.GetTesterAsync(userId); if (tester == null) { tester = await _modelService.SetTesterAsync(new Tester() { UserId = userId }); } var testerGrade = new Marks { FoodItemId = gradeViewModel.SelectedFoodId, TesterId = tester.ID, Grade = await _serializer.SerializeAsync(gradeViewModel.Grade) }; await _modelService.AddScoreAsync(testerGrade); return(RedirectToAction("Results")); }
public async Task Seed() { _ctx.Database.EnsureCreated(); // Ny karakter var newGradeViewModel = new GradeViewModel() { Name = GradeRange.MinusThree }; // Mapping fra GradeViewModel til Grade var newGrade = _mapper.Map <GradeViewModel, Grade>(newGradeViewModel); // Ny bruger var newUserViewModel = new UserViewModel() { UserName = "******", Email = "*****@*****.**", FirstName = "H**o", LastName = "Kaj", }; // Mapping fra UserViewModel til User var newUser = _mapper.Map <UserViewModel, User>(newUserViewModel); // Password til ny bruger var newPassword = "******"; //var newPassword = "******"; var testStudentUser = await _userManager.FindByEmailAsync("*****@*****.**"); if (testStudentUser == null) { // Oprettelse af ny bruger var createNewUser = await _userManager.CreateAsync(newUser, newPassword); if (createNewUser.Succeeded) { // Tilføj bruger til rolle await _userManager.AddToRoleAsync(newUser, Roles.Student.ToString()); } } // Ny klasse var newClassViewModel = new ClassViewModel() { Name = "3b", Year = 2018, Students = new Collection <Student>() }; // Mapping fra ClassViewModel til Class var newClass = _mapper.Map <ClassViewModel, Class>(newClassViewModel); // Ny student var newStudentViewModel = new StudentViewModel() { Grades = new Collection <Grade>(), Class = newClass, User = newUser }; // Mapping fra StudentViewModel til Student var newStudent = _mapper.Map <StudentViewModel, Student>(newStudentViewModel); // Tilføj karakter til student newStudent.Grades.Add(newGrade); // Tilføj student til klasse newClass.Students.Add(newStudent); if (!_ctx.Grades.Any()) { _ctx.Grades.Add(newGrade); } if (!_ctx.Classes.Any()) { _ctx.Classes.Add(newClass); } if (!_ctx.Students.Any()) { _ctx.Students.Add(newStudent); } _ctx.SaveChanges(); }
public EditGrade(string studentName, GradeViewModel grade) : this() { LoadGrade(studentName, grade); }
public GradeViewModel GetGradeById(int gradeId) { GradeViewModel grade = _mapper.Map <GradeViewModel>(_unitOfWork.Grades.GetAll(s => s.GradeId == gradeId, includeProperties: "Student,Course").FirstOrDefault()); return(grade); }
public StudentByClass(GradeViewModel grade) { _grade = grade; }