コード例 #1
0
        public async Task <BLSingleResponse <bool> > EnrollStudentAsync(int subjectId, int userId)
        {
            var response = new BLSingleResponse <bool>();

            try
            {
                //TODO: applay transaction capability
                //using (var trx = await _uow.StartTransactionAsync())
                //{
                //    trx.Commit();
                //}

                var subjEntity = await _uow.GetRepository <Subject>().GetByIdAsync(subjectId);

                if (subjEntity == null)
                {
                    throw new Exception($"Subject Id = {subjectId} didn't match any result.");
                }

                var studentResult = await _uow.GetRepository <Student>().GetByExpressionAsync(s => s.ApplicationUserId == userId);

                StateManager stateManager = await StateManager.GetStateManagerAsync(_studentStateSvc, studentResult.Id, subjectId);

                response.Data = await stateManager.EnrollStudentAsync(
                    _mapperExplicit.MapEntity <Student, StudentDto>(studentResult), _mapperExplicit.MapEntity <Subject, SubjectDto>(subjEntity));
            }
            catch (Exception ex)
            {
                HandleSVCException(response, ex);
            }

            return(response);
        }
コード例 #2
0
ファイル: AccountSvc.cs プロジェクト: Leitee/SchoolMngDemo
        public async Task <BLSingleResponse <UserDto> > RegisterAsync(RegisterDto model)
        {
            var response = new BLSingleResponse <UserDto>();

            var user = _mapper.MapToBaseClass <UserDto, ApplicationUser>(new UserDto(model.Username, model.Email, model.FirstName, model.LastName));

            var signUpResul = await _accountManager.SignUpAsync(user, model.Password);

            if (signUpResul.Succeeded)
            {
                var entity = await _accountManager.UserManager.FindByNameAsync(model.Username);

                response.Data = _mapper.MapEntity <ApplicationUser, UserDto>(entity);
            }
            else
            {
                HandleSVCException(response, signUpResul.Errors.ToList().ConvertAll(x => x.Description).ToArray());
            }

            return(response);
        }