public async Task <ValidationModelResult> Registrate(UserModelResult user) { UserModelEntity userEntity = await _userRepository.GetUser(user.Email); if (userEntity != null) { var errorMessage = new Dictionary <string, string>(); errorMessage.Add("Email", "Email is exist"); return(new ValidationModelResult() { IsValid = false, ErrorMessages = errorMessage }); } user.Password = _securityService.Encrypte(user.Password); userEntity = _mapper.Map <UserModelResult, UserModelEntity>(user); await _userRepository.Create(userEntity); return(new ValidationModelResult() { IsValid = true }); }
public async Task <UserModelResult> Login(LoginModelResult loginModelResult) { var hashPassword = _securityService.Encrypte(loginModelResult.Password); UserModelEntity userEntity = await _userRepository.GetUser(loginModelResult.Username, hashPassword); UserModelResult user = _mapper.Map <UserModelEntity, UserModelResult>(userEntity); return(user); }
public GameParameters(UserModelEntity um, UserModelEntity am, UserModelEntity gm) { _calibration = new Calibration { Duration = 800, Frequency = 1500 }; InitializeComponent(); _xPeople.CurrentItem = um; _xStaircase.CurrentItem = am; _xGameOption.CurrentItem = gm; _xCalDuration.DataContext = _calibration; _xCalFreq.DataContext = _calibration; }
public async Task <UserModelEntity> AddUserAsync(UserModelEntity newUser) { if (newUser.Id == Guid.Empty.ToString()) { newUser.Id = Guid.NewGuid().ToString(); } var dnow = DateTime.UtcNow; newUser.RowVersion = dnow; newUser.JoinedDate = dnow; const string sqlQuery = @"INSERT INTO users ( id, FirstName, LastName, Email, Comment, RowVersion, JoinedDate, ExitDate, Weathers, Password ) VALUES ( @id, @FirstName, @LastName, @Email, @Comment, @RowVersion, @JoinedDate, @ExitDate, @Weathers, @Password);"; using (var db = new MySqlConnection(_options.CurrentValue.UserDbConnectionString)) { await db.ExecuteAsync(sqlQuery, newUser, commandType : CommandType.Text); return(newUser); } }
public static Mock <IUserRepository> UserRepositoryMoq(UserModelEntity userEntity) { var fixture = new Fixture(); var moq = new Mock <IUserRepository>(MockBehavior.Strict); moq.Setup(s => s.CreateUserAsync(It.IsAny <UserModelEntity>())) .ReturnsAsync(userEntity); moq.Setup(s => s.GetUserAsync(It.IsAny <Guid>())) .ReturnsAsync(userEntity); moq.Setup(s => s.UpdateUserAsync(It.IsAny <UserModelEntity>())) .ReturnsAsync(true); moq.Setup(s => s.DeleteUserAsync(It.IsAny <Guid>())) .ReturnsAsync(true); moq.Setup(s => s.GetUserListAsync(It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(fixture.Build <UserModelEntity>().CreateMany(20)); return(moq); }
public async Task <bool> UpdateUserAsync(UserModelEntity user) { user.RowVersion = DateTime.UtcNow; const string sqlQuery = @"UPDATE users SET id = @id, FirstName = @FirstName, LastName = @LastName, Email = @Email, Comment = @Comment, RowVersion = @RowVersion, JoinedDate = @JoinedDate, ExitDate = @ExitDate, Weathers = @Weathers, Password = @Password WHERE id = @id;"; using (var db = new MySqlConnection(_options.CurrentValue.UserDbConnectionString)) { await db.ExecuteAsync(sqlQuery, user, commandType : CommandType.Text); return(true); } }