Exemple #1
0
        public async Task <IDataResult <TokenModel> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <TokenModel>(validation.Message));
            }

            UserDomainService.GenerateHash(signInModel);

            var signedInModel = await UserRepository.SignInAsync(signInModel);

            validation = new SignedInModelValidator().Valid(signedInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <TokenModel>(validation.Message));
            }

            var addUserLogModel = new AddUserLogModel(signedInModel.UserId, LogType.SignIn);

            await UserLogApplicationService.AddAsync(addUserLogModel);

            var tokenModel = UserDomainService.GenerateToken(signedInModel);

            return(new SuccessDataResult <TokenModel>(tokenModel));
        }
Exemple #2
0
        public async Task <IDataResult <long> > AddAsync(AddUserModel addUserModel)
        {
            var validation = new AddUserModelValidator().Valid(addUserModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <long>(validation.Message));
            }

            addUserModel.Login = UserDomainService.GenerateHash(addUserModel.Login);

            addUserModel.Password = UserDomainService.GenerateHash(addUserModel.Password);

            var userDomain = UserDomainFactory.Create(addUserModel);

            userDomain.Add();

            var userEntity = userDomain.Map <UserEntity>();

            await UserRepository.AddAsync(userEntity);

            await DatabaseUnitOfWork.SaveChangesAsync();

            return(new SuccessDataResult <long>(userEntity.UserId));
        }
Exemple #3
0
        public async Task <IDataResult <SignedInModel> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <SignedInModel>(validation.Message));
            }

            signInModel.Login = UserDomainService.GenerateHash(signInModel.Login);

            signInModel.Password = UserDomainService.GenerateHash(signInModel.Password);

            var signedInModel = await UserRepository.SignInAsync(signInModel);

            validation = new SignedInModelValidator().Valid(signedInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <SignedInModel>(validation.Message));
            }

            await AddUserLogAsync(signedInModel.UserId, LogType.SignIn).ConfigureAwait(false);

            return(new SuccessDataResult <SignedInModel>(signedInModel));
        }
        public async Task <IDataResult <SignedInModel> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(ErrorDataResult <SignedInModel>(validation.Message));
            }

            UserDomainService.GenerateHash(signInModel);

            var signedInModel = await UserRepository.SignInAsync(signInModel);

            validation = new SignedInModelValidator().Valid(signedInModel);

            if (!validation.Success)
            {
                return(ErrorDataResult <SignedInModel>(validation.Message));
            }

            return(SuccessDataResult(signedInModel));
        }