public async Task <bool> AddTransactionAsync(DBTransaction tr) { if (!tr.IsValid) { throw new ArgumentException("Transaction isn`t valid."); } await _storage.AddOrUpdateAsync(tr); return(true); }
public async Task <bool> AddWalletsAsync(DBWallet wallet) { if (String.IsNullOrWhiteSpace(wallet.Name) || wallet.Balance < 0) { throw new ArgumentException("Name or Balance is Empty."); } await _storage.AddOrUpdateAsync(wallet); return(true); }
public async Task <bool> AddOrUpdateWalletAsync(Wallet wallet) { Thread.Sleep(1000); await Task.Run(() => _storage.AddOrUpdateAsync(wallet)); return(true); }
public async Task <bool> AddOrUpdateCategoryAsync(Category category) { Thread.Sleep(1000); await Task.Run(() => _storage.AddOrUpdateAsync(category)); return(true); }
public async Task <bool> RegisterUserAsync(RegistrationUser regUser) { Thread.Sleep(2000); var users = await _storage.GetAllAsync(); var dbUser = users.FirstOrDefault(user => user.Login == regUser.Login); if (dbUser != null) { throw new Exception("User already exists"); } if (String.IsNullOrWhiteSpace(regUser.Login) || String.IsNullOrWhiteSpace(regUser.Password) || String.IsNullOrWhiteSpace(regUser.LastName)) { throw new ArgumentException("Login, Password or Last Name is Empty"); } ////encrypt pswd // PasswordEncrypter.CreateEncryptionKey(); string encryptedPswd = PasswordEncrypter.Encrypt(regUser.Password); dbUser = new DBUser(regUser.LastName + regUser.FirstName, regUser.LastName, regUser.Email, regUser.Login, encryptedPswd); await _storage.AddOrUpdateAsync(dbUser); return(true); }
public async Task <bool> AddOrUpdateTransactionAsync(Transaction transaction) { Thread.Sleep(1000); await Task.Run(() => _storage.AddOrUpdateAsync(transaction)); return(true); }
public async Task <bool> RecordCategories(User user) { UserDb userDb = await _storage.GetAsync(user.Guid); userDb.Categories = user.Categories; await _storage.AddOrUpdateAsync(userDb); return(true); }
public async Task SaveChanges() { await _storage.DeleteAllFiles(User.Id.ToString("N")); foreach (var category in Categories) { var dbCategory = new DBCategory(category.Name, category.Owner.Id.ToString("N"), category.Description, category.Color, category.Icon, category.Id); await _storage.AddOrUpdateAsync(dbCategory); } }
public async Task SaveChanges() { await _storage.DeleteAllFiles(Wallet.Id.ToString("N")); foreach (var transaction in _transactions) { var dbTransaction = new DBTransaction(transaction.Wallet.Id.ToString("N"), transaction.Sum, transaction.Currency, transaction.Description, transaction.Date, transaction.Category.Name, transaction.Id); await _storage.AddOrUpdateAsync(dbTransaction); } }
public async Task SaveChanges() { await _storage.DeleteAllFiles(User.Id.ToString("N")); foreach (var wallet in Wallets) { var dbWallet = new DBWallet(wallet.Name, wallet.Owner.Id.ToString("N"), wallet.Description, wallet.InitialBalance, wallet.CurrentBalance, wallet.MainCurrency, wallet.Id, wallet.AvailabilityOfCategories); await _storage.AddOrUpdateAsync(dbWallet); } }
public async Task AddOrUpdateWallet(SaveWallet saveWallet) { await Task.Run(async() => { // Thread.Sleep(1000); await _storage.AddOrUpdateAsync(new DBWallet ( saveWallet.Guid, saveWallet.Name, saveWallet.Description, saveWallet.Currency, saveWallet.InitialBalance, saveWallet.OwnerGuid )); }); }
public async Task AddOrUpdateTransaction(SaveTransaction saveTransaction) { await Task.Run(async() => { // Thread.Sleep(1000); await _storage.AddOrUpdateAsync(new DBTransaction ( saveTransaction.Guid, saveTransaction.Sum, saveTransaction.Currency, saveTransaction.Category, saveTransaction.Description, saveTransaction.Date )); }); }
public async Task Register(RegUser regUser) { await Task.Run(async() => { // Thread.Sleep(1000); if (string.IsNullOrWhiteSpace(regUser.Login) || string.IsNullOrWhiteSpace(regUser.Password) || string.IsNullOrWhiteSpace(regUser.FirstName) || string.IsNullOrWhiteSpace(regUser.LastName) || string.IsNullOrWhiteSpace(regUser.Email)) { throw new ArgumentException("Some fields are empty"); } if (!new EmailAddressAttribute().IsValid(regUser.Email)) { throw new ArgumentException("Email is invalid"); } List <DBUser> users = await _storage.GetAllAsync(); DBUser dbUser = users.FirstOrDefault(user => user.Login == regUser.Login); if (dbUser != null) { throw new Exception("User already exists"); } byte[] encryptedPassword = System.Text.Encoding.ASCII.GetBytes(regUser.Password); encryptedPassword = new System.Security.Cryptography.SHA256Managed().ComputeHash(encryptedPassword); string hashPassword = System.Text.Encoding.ASCII.GetString(encryptedPassword); await _storage.AddOrUpdateAsync(new DBUser ( Guid.NewGuid(), regUser.Login, hashPassword, regUser.FirstName, regUser.LastName, regUser.Email )); }); }
public async Task <bool> RegistrateUser(RegistrationUser regUser) { Thread.Sleep(2000); var users = await _storage.GetAllAsync(); var dbUser = users.FirstOrDefault(user => user.Login == regUser.Login); if (dbUser != null) { throw new Exception("User with this login already exists"); } if (String.IsNullOrWhiteSpace(regUser.Login) || String.IsNullOrWhiteSpace(regUser.Password) || String.IsNullOrWhiteSpace(regUser.LastName) || String.IsNullOrWhiteSpace(regUser.FirstName) || String.IsNullOrWhiteSpace(regUser.Email)) { throw new ArgumentException("Some of fields are empty."); } if (!Regex.IsMatch(regUser.Email, @"[a-zA-Z0-9]+@[a-z]+(\.)[a-z]+$")) // regex for email { throw new ArgumentException("Invalid email"); } if (regUser.Login.Length > 30 || regUser.Password.Length > 30 || regUser.LastName.Length > 30 || regUser.FirstName.Length > 30) { throw new ArgumentException("All the fields should be not more than 30 symbols"); } if (regUser.Login.Length < 3 || regUser.Password.Length < 3 || regUser.LastName.Length < 3 || regUser.FirstName.Length < 3) { throw new ArgumentException("All the fields should be not less than 3 symbols"); } dbUser = new DBUser(Guid.NewGuid(), regUser.FirstName, regUser.LastName, regUser.Email, regUser.Login, Encrypt(regUser.Password)); await _storage.AddOrUpdateAsync(dbUser); return(true); }
public async Task <bool> RegistrateUser(RegistrationUser regUser) { Thread.Sleep(2000); var users = await Task.Run(() => _storage.GetAllAsync()); var dbUser = users.FirstOrDefault(user => user.Login == regUser.Login); if (dbUser != null) { throw new Exception("There's already user with this login"); } if (string.IsNullOrWhiteSpace(regUser.Login) || string.IsNullOrWhiteSpace(regUser.Password) || string.IsNullOrWhiteSpace(regUser.Name.Name) || string.IsNullOrWhiteSpace(regUser.Name.Surname) || string.IsNullOrWhiteSpace(regUser.Email.ToString())) { throw new ArgumentException("Fill all the fields!"); } if (!Regex.IsMatch(regUser.Email.ToString(), @"[a-zA-Z0-9]+@[a-z]+(\.)[a-z]+$")) { throw new ArgumentException("Invalid email"); } if (regUser.Login.Length > 30 || regUser.Password.Length > 30 || regUser.Name.Surname.Length > 30 || regUser.Name.Name.Length > 30) { throw new ArgumentException("Too long login/password/name/surname"); } if (regUser.Login.Length < 3 || regUser.Password.Length < 3 || regUser.Name.Surname.Length < 3 || regUser.Name.Name.Length < 3) { throw new ArgumentException("Too short login/password/name/surname"); } dbUser = new DBUser(Guid.NewGuid(), regUser.Name, regUser.Email, regUser.Login, Encrypt(regUser.Password)); await _storage.AddOrUpdateAsync(dbUser); return(true); }
public async Task <bool> RegisterUserAsync(RegistrationUser regUser) { Thread.Sleep(2000); var users = await _storage.GetAllAsync(); var dbUser = users.FirstOrDefault(user => user.Login == regUser.Login); if (dbUser != null) { throw new Exception("User already exists"); } if (String.IsNullOrWhiteSpace(regUser.Login) || String.IsNullOrWhiteSpace(regUser.Password) || String.IsNullOrWhiteSpace(regUser.LastName)) { throw new ArgumentException("Login, Password or Last Name is Empty"); } dbUser = new DBUser(regUser.LastName + "First", regUser.LastName, regUser.Login + "@gmail.com", regUser.Login, regUser.Password); await _storage.AddOrUpdateAsync(dbUser); return(true); }
public async Task <bool> RegisterUserAsync(RegistrationUser regUser) { Thread.Sleep(1000); var users = await _storage.GetAllAsync(DBUser.FOLDER); var dbUser = users.FirstOrDefault(user => user.Login == regUser.Login); if (dbUser != null) { throw new Exception("User already exists"); } if (String.IsNullOrWhiteSpace(regUser.Name) || String.IsNullOrWhiteSpace(regUser.LastName) || String.IsNullOrWhiteSpace(regUser.Email) || String.IsNullOrWhiteSpace(regUser.Login) || String.IsNullOrWhiteSpace(regUser.Password)) { throw new ArgumentException("At least one field is empty"); } if ((regUser.Name.Length < 2) || (regUser.LastName.Length < 2) || (regUser.Login.Length < 2) || (regUser.Name.Length > 50) || (regUser.LastName.Length > 50) || (regUser.Login.Length > 50)) { throw new ArgumentException("First name, last name and login must consist at least of 2 symbols. Max 50"); } if (!Regex.IsMatch(regUser.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$")) { throw new ArgumentException("Incorrect email"); } if ((regUser.Password.Length < 3)) { throw new ArgumentException("Password must consist at least of 3 symbols"); } string encryptedPassword = Encrypt(regUser.Password, encryptingIndex); dbUser = new DBUser(regUser.Name, regUser.LastName, regUser.Login + "@gmail.com", regUser.Login, encryptedPassword); await _storage.AddOrUpdateAsync(dbUser); return(true); }
public async Task <bool> RegisterUserAsync(UserReg regUser) { var users = await _storage.GetAllAsync(); var dbUser = users.FirstOrDefault(user => user.Login == regUser.Login); if (dbUser != null) { throw new UserException("User already exists"); } if (String.IsNullOrWhiteSpace(regUser.Login) || String.IsNullOrWhiteSpace(regUser.Name) || String.IsNullOrWhiteSpace(regUser.Surname) || String.IsNullOrWhiteSpace(regUser.Password) || String.IsNullOrWhiteSpace(regUser.Email)) { throw new ArgumentException("Login, Password, Name, Surname or Email is Empty"); } dbUser = new UserDb(regUser.Login, Encryption.Encrypt(regUser.Password, regUser.Password), regUser.Name, regUser.Surname, regUser.Email); await _storage.AddOrUpdateAsync(dbUser); return(true); }