Example #1
0
        public async Task <ResultSpec <bool> > Update(StudentAddUpdateModel studentAddUpdateModel)
        {
            var today = await _dateTimeProvider.GetTodayDateTime();

            var specResult = StudentAddUpdateSpec.IsSatisfiedBy(studentAddUpdateModel, 18, today);

            if (specResult.OverallResult)
            {
                using (var scope = new TransactionScope(
                           TransactionScopeOption.Required,
                           new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                }))
                {
                    var student = _mapper.Map(studentAddUpdateModel, new Student());

                    await _asyncStudentRepository.Update(student);

                    await _asyncStudentRepository.Save();

                    scope.Complete();

                    return(Results.WithOkSpec(true).AddMessage(Resource.Successful));
                }
            }
            else
            {
                return(Results.WithFailSpec(false).AddSpec(specResult).AddMessage(Resource.Unsuccessfull));
            }
        }
Example #2
0
        public async Task <ResultSpec <int> > Add(StudentAddUpdateModel studentAddUpgdateModel)
        {
            var today = await _dateTimeProvider.GetTodayDateTime();

            var specResult = StudentAddUpdateSpec.IsSatisfiedBy(studentAddUpgdateModel, StudentDomainConstants.MinAgeForStudent, today);

            if (specResult.OverallResult)
            {
                //using (var scope = new TransactionScope(
                //    TransactionScopeOption.Required,
                //    new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
                //{
                var student    = _mapper.Map <Student>(studentAddUpgdateModel.Student);
                var newStudent = await _asyncStudentRepository.Insert(student);

                try
                {
                    await _asyncStudentRepository.Save();
                }
                catch (Exception e)
                {
                    var d = e;
                    throw;
                }

                //scope.Complete();

                return(Results.WithOkSpec <int>(newStudent.Id).AddMessage(Resource.Successful).AddSpec(specResult));
                //}
            }
            else
            {
                return(Results.WithFailSpec <int>(-1).AddSpec(specResult));
            }
        }