public Student TryAddStudent(StudentContract studentContract, out string message) { if (!Utilities.IsValidStudentContract(studentContract, out message)) { return(null); } try { // Assuming 2 people can have the exact same name, but not the same email address if (_studentRepository.IsStudentWithSameEmailAddressExist(studentContract.EmailAddress)) { message = "Student with the same email address is already exist"; return(null); } var student = new Student(studentContract); return(_studentRepository.AddStudent(student)); } catch (DALException e) { // LOG throw new BLException("There was a problem adding new student", e); } }
public async Task Should_pass_params_Correctly() { var contract = new StudentContract() { Gender = Gender.Male, Family = "Krasavin", Name = "Daniil", SureName = "Jurevich", StudentId = "candidate" }; studentRepository.Setup(r => r.Insert(It.IsAny <StudentModel>())).ReturnsAsync((StudentModel model) => { model.Name.Should().Be(contract.Name); model.Gender.Should().Be((int)contract.Gender); model.Family.Should().Be(contract.Family); model.SureName.Should().Be(contract.SureName); model.StudentId.Should().Be(contract.StudentId); return(1); }); var result = await sut.Create(contract); studentRepository.VerifyAll(); }
public Student TryUpdateStudentDetails(int studentId, StudentContract studentContract, out string message) { if (!Utilities.IsValidStudentContract(studentContract, out message)) { return(null); } try { var student = _studentRepository.GetStudentById(studentId); if (student == null) { message = "Student with matching id doesn't exist"; return(null); } student.UpdateFromContract(studentContract); return(_studentRepository.UpdateStudentDetails(studentId, student)); } catch (DALException e) { // LOG throw new BLException("There was a problem updating student details", e); } }
public async Task Update(StudentContract student) { await studentContractValidator.ValidateAndThrowAsync(student); var model = mapper.Map <StudentModel>(student); await studentRepository.Update(model); }
public async Task <long> Create(StudentContract student) { await studentContractValidator.ValidateAndThrowAsync(student); var model = mapper.Map <StudentModel>(student); return(await studentRepository.Insert(model)); }
public StudentContractUnitTests() { _fixture.Behaviors.OfType <ThrowingRecursionBehavior>().ToList() .ForEach(b => _fixture.Behaviors.Remove(b)); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _sut = new StudentContract(_studentRepository, _context); }
public static bool IsValidStudentContract(StudentContract studentContract, out string message) { if (string.IsNullOrEmpty(studentContract.FirstName) || string.IsNullOrEmpty(studentContract.LastName) || !Utilities.IsValidEmail(studentContract.EmailAddress)) { message = "Please fill all field and enter a valid email address"; return(false); } message = String.Empty; return(true); }
public async Task Should_throw_on_long_name() { var contract = new StudentContract() { Gender = Gender.Male, Family = "Krasavin", Name = "11111111111111111111111111111111111111111111111111111", SureName = "Jurevich", StudentId = "candidate" }; var act = new Func <Task>(async() => await sut.Create(contract)); await act.Should().ThrowAsync <ValidationException>(); }
public IActionResult AddStudent([FromBody] StudentContract studentContract) { try { var student = _businessLogic.TryAddStudent(studentContract, out var message); if (student == null) { return(BadRequest(message)); } return(Ok(student)); } catch (BLException e) { // Log here return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public IActionResult UpdateStudentDetails(int id, [FromBody] StudentContract studentContract) { try { var course = _businessLogic.TryUpdateStudentDetails(id, studentContract, out var message); if (course == null) { return(BadRequest(message)); } return(Ok(course)); } catch (BLException e) { // Log here return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public ContractViewModel(StudentContract contract) { Contract = contract; }
public void UpdateFromContract(StudentContract studentContract) { EmailAddress = studentContract.EmailAddress; FirstName = studentContract.FirstName; LastName = studentContract.LastName; }
public Student(StudentContract studentContract) { FirstName = studentContract.FirstName; LastName = studentContract.LastName; EmailAddress = studentContract.EmailAddress; }
public ContractDocument(StudentContract _contract) { contract = _contract; DocumentType = OpenXmlDocumentType.Document; }