Example #1
0
        public void Should_Be_Invalid_When_Surnames_Are_Same()
        {
            //Arrange
            IEnumerable <Student> students = new List <Student>()
            {
                new Student()
                {
                    Age = 6, FirstName = "Mike", GPA = 1.04, Id = 1, SurName = "Hazle"
                },
                new Student()
                {
                    Age = 8, FirstName = "Steph", GPA = 3.04, Id = 2, SurName = "Viel"
                }
            };

            _mockStudentRepository.Setup(t => t.GetStudentsBySubjectIdAsync(It.IsAny <int>())).Returns(Task.FromResult(students));
            var inputModel = new StudentAddModel()
            {
                Age = 8, FirstName = "Steph", GPA = 3.04, SurName = "Viel", SubjectId = 12
            };

            //Act
            var quantumITAppService = new QuantumITAppService(_mockSubjectRepository.Object, _mockStudentRepository.Object, _mockMapper.Object);
            var actualResult        = quantumITAppService.ValidStudent(inputModel);

            //Assert
            actualResult.Result.Should().BeFalse();
        }
Example #2
0
        public Result <StudentResultDTO> CreateStudent(StudentAddModel model)
        {
            var check = studentDAL.Get(w => w.UserID == model.UserID && w.Class_ID == model.ClassID);

            if (check != null)
            {
                var checkuser = userDAL.Get(w => w.ID == model.UserID && w.UserType == Entity.Concrete.UserType.Student);
                if (checkuser == null)
                {
                    return(new Result <StudentResultDTO>(true, "boyle bir kullanici yok", null));
                }
                Student student = new Student()
                {
                    UserID   = model.UserID,
                    Class_ID = model.ClassID
                };

                studentDAL.Add(student);
                return(new Result <StudentResultDTO>(false, "isleminizi basari ile gerceklemistir", null));
            }
            else
            {
                return(new Result <StudentResultDTO>(true, "boyle bir kayit mevcuttur", null));
            }
        }
        public async Task <ActionResult <Student> > PostStudent([FromBody] StudentAddModel sam)
        {
            Student student = new Student
            {
                OpenId    = sam.OpenId,
                StudentId = sam.StudentId,
                Name      = sam.Name,
                Sclass    = sam.Sclass,
                Pwd       = sam.Pwd,
                Avatar    = sam.Avatar
            };

            _context.Student.Add(student);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (StudentExists(sam.OpenId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetStudent", new { id = student.OpenId }, student));
        }
Example #4
0
        public async Task <IActionResult> AddStudent([FromBody] StudentAddModel studentToAdd)
        {
            var student = await _quantumITAppService.AddStudentAsync(studentToAdd);

            return(Ok(student));

            throw new Exception($"adding new student failed!");
        }
        public async Task <IActionResult> AddStudent([FromBody] StudentAddModel studentToAdd)
        {
            var student = await _quantumITAppService.AddStudentAsync(studentToAdd);

            if (!student)
            {
                return(BadRequest(_error));
            }
            return(Ok(student));
        }
Example #6
0
        public async Task <bool> AddStudentAsync(StudentAddModel studentToAdd)
        {
            var student = _mapper.Map <Student>(studentToAdd);

            if (await ValidStudent(studentToAdd))
            {
                return(await _studentRepository.AddSubjectStudentAsync(student, studentToAdd.SubjectId));
            }

            return(false);
        }
Example #7
0
 public Result <StudentResultDTO> CreateStudent(StudentAddModel model)
 {
     try
     {
         return(studentService.CreateStudent(model));
     }
     catch (Exception e)
     {
         return(new Result <StudentResultDTO>(true, e.Message, null));
     }
 }
Example #8
0
        public async Task <bool> ValidStudent(StudentAddModel studentToAdd)
        {
            var students = await _studentRepository.GetStudentsBySubjectIdAsync(studentToAdd.SubjectId);

            var studentFound = students.FirstOrDefault(st => st.SurName == studentToAdd.SurName);

            if (studentFound == null)
            {
                return(true);
            }
            return(false);
        }
        public async Task <IActionResult> Add([FromBody] StudentAddModel model)
        {
            try
            {
                var student    = _mapper.Map <StudentDto>(model);
                var savedModel = await _studentService.Add(student);

                var result = _mapper.Map <StudentModel>(savedModel);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Unable to add student: {model.ToString()}");
                return(this.InternalServerError(ex));
            }
        }
Example #10
0
        public async Task <IActionResult> Insert(StudentAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dto = _mapper.Map <StudentDto>(model);

            try
            {
                int id = await _studentService.AddStudent(dto);

                return(CreatedAtRoute("Student Get", new { Id = id }, new StudentModel(id, model.FullName, model.Email)));
            }
            catch (IncorrectIdException e)
            {
                _logger.LogWarning(e, "It seems, validation does not cover some errors.");
                return(BadRequest(e.Message));
            }
        }
Example #11
0
        [AutoValidateAntiforgeryToken]//验证post token
        public IActionResult Create(StudentAddModel student)
        {
            if (ModelState.IsValid)
            {
                var newStudent = new Student
                {
                    FirstName = student.FirstName,
                    LastName  = student.LastName,
                    Birthday  = student.Birthday,
                    Gender    = student.Gender
                };

                var result = _repository.Add(newStudent);

                return(RedirectToAction(nameof(Detail), new { id = result.Id }));
            }

            ModelState.AddModelError(string.Empty, "model empty error");

            return(View());
        }