Ejemplo n.º 1
0
        public async Task <IDataResult <long> > AddAsync(AddUserModel addUserModel)
        {
            var validation = new AddUserModelValidator().Valid(addUserModel);

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

            UserDomainService.GenerateHashForLoginAndPassword(addUserModel.SignIn);

            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));
        }
Ejemplo n.º 2
0
        public async Task <IDataResult <SignedInModel> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

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

            UserDomainService.GenerateHashForLoginAndPassword(signInModel);

            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));
        }