public async Task <IDataResult <TokenModel> > SignInAsync(SignInModel signInModel) { var validation = new SignInModelValidator().Validate(signInModel); if (validation.Failed) { return(DataResult <TokenModel> .Fail(validation.Message)); } var signedInModel = await _userRepository.SignInAsync(signInModel); validation = _signInService.Validate(signedInModel, signInModel); if (validation.Failed) { return(DataResult <TokenModel> .Fail(validation.Message)); } var userLogModel = new UserLogModel(signedInModel.Id, LogType.SignIn); await _userLogApplicationService.AddAsync(userLogModel); var tokenModel = _signInService.CreateToken(signedInModel); return(DataResult <TokenModel> .Success(tokenModel)); }
public async Task <IDataResult <long> > AddAsync(AddUserModel addUserModel) { var validation = new AddUserModelValidator().Validate(addUserModel); if (validation.Failed) { return(DataResult <long> .Fail(validation.Message)); } addUserModel.SignIn = _signInService.CreateSignIn(addUserModel.SignIn); var userEntity = UserFactory.Create(addUserModel); userEntity.Add(); await _userRepository.AddAsync(userEntity); await _unitOfWork.SaveChangesAsync(); return(DataResult <long> .Success(userEntity.Id)); }
public async Task <IDataResult <TokenModel> > SignInAsync(SignInModel signInModel) { var validation = new SignInModelValidator().Validate(signInModel); if (validation.Failed) { return(DataResult <TokenModel> .Fail(validation.Message)); } var authEntity = await _authRepository.GetByLoginAsync(signInModel.Login); validation = Validate(authEntity, signInModel); if (validation.Failed) { return(DataResult <TokenModel> .Fail(validation.Message)); } var tokenModel = CreateToken(authEntity); return(DataResult <TokenModel> .Success(tokenModel)); }
public async Task <DataResult <SolutionData> > ScanSolution() { var solutionData = new SolutionData(); try { await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = (DTE)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(DTE)); string solutionDirectory = System.IO.Path.GetDirectoryName(dte.Solution.FullName); var sln = Microsoft.Build.Construction.SolutionFile.Parse(dte.Solution.FullName); string summaryText = $"{sln.ProjectsInOrder.Count.ToString()} projects"; foreach (Project p in dte.Solution.Projects) { System.Diagnostics.Debug.WriteLine($"Project {p.Name}"); var projectData = new ProjectData() { Name = p.Name }; await ScanProjectItems(p.ProjectItems, projectData, solutionDirectory); if (projectData?.Items?.Count > 0) { solutionData.ProjectData.Add(projectData); } } return(DataResult <SolutionData> .Success(solutionData)); } catch { return(DataResult <SolutionData> .Fail("Solution is not ready yet.")); } }
public async Task <IDataResult <long> > AddAsync(AddUserModel addUserModel) { var validation = new AddUserModelValidator().Validate(addUserModel); if (validation.Failed) { return(DataResult <long> .Fail(validation.Message)); } var authEntityResult = await _authApplicationService.AddAsync(addUserModel.Auth); if (authEntityResult.Failed) { return(DataResult <long> .Fail(authEntityResult.Message)); } var userEntity = UserFactory.Create(addUserModel, authEntityResult.Data); await _userRepository.AddAsync(userEntity); await _unitOfWork.SaveChangesAsync(); return(DataResult <long> .Success(userEntity.Id)); }
public async Task <IDataResult <AuthEntity> > AddAsync(AuthModel authModel) { var validation = new AuthModelValidator().Validate(authModel); if (validation.Failed) { return(DataResult <AuthEntity> .Fail(validation.Message)); } if (await _authRepository.AnyByLoginAsync(authModel.Login)) { return(DataResult <AuthEntity> .Fail(Texts.AuthError)); } var authEntity = AuthFactory.Create(authModel); var password = _hashService.Create(authEntity.Password, authEntity.Salt); authEntity.ChangePassword(password); await _authRepository.AddAsync(authEntity); return(DataResult <AuthEntity> .Success(authEntity)); }
public DataResult <User> Login(LoginUser loginUser) { //TODO validation; //TODO get User with db Result result = _validate.LoginUser(loginUser); if (!result.Success) { return(DataResult <User> .Fail()); } return(new DataResult <User>() { Success = true, Data = new User() { FirstName = "default", LastName = "default", Login = loginUser.Login, Password = loginUser.Password } }); }