public BooleanErrorModel Register(UserModel user) { var returnodel = new BooleanErrorModel(); try { if (user != null) { var entetiUser = _Mapper.Map <User>(user); entetiUser.Password = _PasswordEngine.GetHash(string.Concat(entetiUser.Password, _identity.Value.Salt)); entetiUser.Accounts.Add(new Account() { Balance = 0 }); _UOF.Users.Add(entetiUser); _UOF.Save(); returnodel.Error = false; return(returnodel); } returnodel.Error = true; returnodel.ErrorMessage = "Empty user data."; return(returnodel); } catch (Exception exception) { returnodel.Error = true; returnodel.ErrorMessage = "Thomething goes wrong!"; return(returnodel); } }
public BooleanErrorModel Transfer(double amount, string userInitiatorName, string userReceiverName) { var returnModel = new BooleanErrorModel(); try { var userInitiator = _Unit.Accounts.Get(userInitiatorName); if (userInitiator == null) { returnModel.ErrorMessage = "Unknown initiator";; returnModel.Error = true; return(returnModel); } if (userInitiator.Balance < amount) { returnModel.ErrorMessage = "Not enoth money"; returnModel.Error = true; return(returnModel); } if (amount <= 0) { returnModel.ErrorMessage = "Amount less that 1"; returnModel.Error = true; return(returnModel); } var userReceiver = _Unit.Accounts.Get(userReceiverName); if (userReceiver == null) { returnModel.ErrorMessage = "Unknown reciver"; returnModel.Error = true; return(returnModel); } var error = false; var errorMessage = string.Empty; var transaction = CreateTransaction(amount, userInitiator, userReceiver, 3, ref error, ref errorMessage); if (error) { returnModel.ErrorMessage = errorMessage; returnModel.Error = true; return(returnModel); } _Unit.Transaction.Add(transaction); userInitiator.Balance -= amount; userReceiver.Balance += amount; _Unit.Save(); return(returnModel); } catch (Exception exception) { returnModel.ErrorMessage = "Thomething goes wrong!"; returnModel.Error = true; return(returnModel); } }
public BooleanErrorModel Withdraw(string userName, double amount) { var returnModel = new BooleanErrorModel(); try { var account = _Unit.Accounts.Get(userName); if (account.Balance < amount) { returnModel.ErrorMessage = "Not enoth money"; returnModel.Error = true; return(returnModel); } if (amount <= 0) { returnModel.ErrorMessage = "Amount less that 1"; returnModel.Error = true; return(returnModel); } account.Balance -= amount; var error = false; var errorMessage = string.Empty; var transaction_ = CreateTransaction(amount, account, account, 2, ref error, ref errorMessage); if (error) { returnModel.ErrorMessage = errorMessage; returnModel.Error = true; return(returnModel); } _Unit.Transaction.Add(transaction_); _Unit.Save(); return(returnModel); } catch (Exception exception) { returnModel.ErrorMessage = "Thomething goes wrong!"; returnModel.Error = true; return(returnModel); } }