Example #1
0
        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);
            }
        }
Example #2
0
        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();
        }
Example #3
0
        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);
            }
        }
Example #4
0
        public async Task Update(StudentContract student)
        {
            await studentContractValidator.ValidateAndThrowAsync(student);

            var model = mapper.Map <StudentModel>(student);
            await studentRepository.Update(model);
        }
Example #5
0
        public async Task <long> Create(StudentContract student)
        {
            await studentContractValidator.ValidateAndThrowAsync(student);

            var model = mapper.Map <StudentModel>(student);

            return(await studentRepository.Insert(model));
        }
Example #6
0
        public StudentContractUnitTests()
        {
            _fixture.Behaviors.OfType <ThrowingRecursionBehavior>().ToList()
            .ForEach(b => _fixture.Behaviors.Remove(b));

            _fixture.Behaviors.Add(new OmitOnRecursionBehavior());

            _sut = new StudentContract(_studentRepository, _context);
        }
Example #7
0
        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);
        }
Example #8
0
        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>();
        }
Example #9
0
        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));
            }
        }
Example #10
0
        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));
            }
        }
Example #11
0
 public ContractViewModel(StudentContract contract)
 {
     Contract = contract;
 }
Example #12
0
 public void UpdateFromContract(StudentContract studentContract)
 {
     EmailAddress = studentContract.EmailAddress;
     FirstName    = studentContract.FirstName;
     LastName     = studentContract.LastName;
 }
Example #13
0
 public Student(StudentContract studentContract)
 {
     FirstName    = studentContract.FirstName;
     LastName     = studentContract.LastName;
     EmailAddress = studentContract.EmailAddress;
 }
Example #14
0
 public ContractDocument(StudentContract _contract)
 {
     contract     = _contract;
     DocumentType = OpenXmlDocumentType.Document;
 }