コード例 #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);
            }
        }
コード例 #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();
        }
コード例 #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);
            }
        }
コード例 #4
0
ファイル: StudentService.cs プロジェクト: Gutse/VelvetechTZ
        public async Task Update(StudentContract student)
        {
            await studentContractValidator.ValidateAndThrowAsync(student);

            var model = mapper.Map <StudentModel>(student);
            await studentRepository.Update(model);
        }
コード例 #5
0
ファイル: StudentService.cs プロジェクト: Gutse/VelvetechTZ
        public async Task <long> Create(StudentContract student)
        {
            await studentContractValidator.ValidateAndThrowAsync(student);

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

            return(await studentRepository.Insert(model));
        }
コード例 #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);
        }
コード例 #7
0
ファイル: Utilities.cs プロジェクト: Omerh84/Cycode
        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);
        }
コード例 #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>();
        }
コード例 #9
0
ファイル: StudentsController.cs プロジェクト: Omerh84/Cycode
        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));
            }
        }
コード例 #10
0
ファイル: StudentsController.cs プロジェクト: Omerh84/Cycode
        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));
            }
        }
コード例 #11
0
 public ContractViewModel(StudentContract contract)
 {
     Contract = contract;
 }
コード例 #12
0
ファイル: Student.cs プロジェクト: Omerh84/Cycode
 public void UpdateFromContract(StudentContract studentContract)
 {
     EmailAddress = studentContract.EmailAddress;
     FirstName    = studentContract.FirstName;
     LastName     = studentContract.LastName;
 }
コード例 #13
0
ファイル: Student.cs プロジェクト: Omerh84/Cycode
 public Student(StudentContract studentContract)
 {
     FirstName    = studentContract.FirstName;
     LastName     = studentContract.LastName;
     EmailAddress = studentContract.EmailAddress;
 }
コード例 #14
0
 public ContractDocument(StudentContract _contract)
 {
     contract     = _contract;
     DocumentType = OpenXmlDocumentType.Document;
 }