public async Task <Entity> InsertAsync(Entity entity) { if (_crudValidator != null) { await _crudValidator.InsertAsync(entity); } return(await _crudManager.InsertAsync(entity)); }
public async Task <SignUpResponse> SignUpAsync(SignupViewModel signUp) { return(await Task.Run(async() => { var user = await _user.CreateUserAsync(signUp); if (!await _user.IsExistAsync(user.UserName)) { if (await _userCrud.InsertAsync(user) && await _userCrud.SaveAsync()) { return SignUpResponse.Success; } return SignUpResponse.Exception; } return SignUpResponse.UserAlreadyExist; })); }
public async Task <LoginResponse> LoginAsync(LoginViewModel login, bool rememmeberMe, int expireDays = 20, HttpContext context = null) { return(await Task.Run(async() => { LoginResponse response = new(); Users user = await _user.GetUserByEmailAsync(login.Email); if (user != null) { if (await CheckPasswordAsync(user, login.Password)) { Tokens token = await CreateTokenAsync(user, expireDays); if (await _tokenCrud.InsertAsync(token) && await _tokenCrud.SaveAsync()) { LoginLogs log = await CreateLogAsync(token, context); await _logCrud.InsertAsync(log); await _logCrud.SaveAsync(); //Create Success Type if (rememmeberMe) { response.Success = new Success { IsSucces = true, Key = token.TokenKey, Value = token.TokenValue }; } response.Status = LoginStatus.Success; return response; } response.Status = LoginStatus.Exception; return response; } response.Status = LoginStatus.WrongPassword; return response; } response.Status = LoginStatus.UserNotFound; return response; })); }