public async Task <Transfer> CreateTransfer(Transfer transfer) { var walletRepository = ContextProvider.GetRepository <IWalletRepository>(); transfer.SourceWallet = walletRepository.GetByKey(transfer.SourceWalletId); if (transfer.SourceWallet == null) { throw new CashSchedulerException("There is no such wallet", new[] { "sourceWalletId" }); } transfer.TargetWallet = walletRepository.GetByKey(transfer.TargetWalletId); if (transfer.TargetWallet == null) { throw new CashSchedulerException("There is no such wallet", new[] { "targetWalletId" }); } ModelValidator.ValidateModelAttributes(transfer); transfer.SourceWallet.Balance -= transfer.Amount; if (transfer.SourceWallet.Balance < 0) { throw new CashSchedulerException("There is not enough money on the wallet", new[] { "amount" }); } await walletRepository.Update(transfer.SourceWallet); transfer.TargetWallet.Balance += transfer.ExchangeRate * transfer.Amount; await walletRepository.Update(transfer.TargetWallet); return(transfer); }
public Task <User> Create(User user) { ModelValidator.ValidateModelAttributes(user); user.Password = user.Password.Hash(Configuration); return(UserRepository.Create(user)); }
public async Task <User> Update(User user) { ModelValidator.ValidateModelAttributes(user); Context.Users.Update(user); await Context.SaveChangesAsync(); return(user); }
public async Task <UserRefreshToken> Update(UserRefreshToken refreshToken) { ModelValidator.ValidateModelAttributes(refreshToken); Context.UserRefreshTokens.Update(refreshToken); await Context.SaveChangesAsync(); return(refreshToken); }
public async Task <Wallet> Update(Wallet wallet) { ModelValidator.ValidateModelAttributes(wallet); Context.Wallets.Update(wallet); await Context.SaveChangesAsync(); return(wallet); }
public async Task <RegularTransaction> Update(RegularTransaction transaction) { ModelValidator.ValidateModelAttributes(transaction); Context.RegularTransactions.Update(transaction); await Context.SaveChangesAsync(); return(transaction); }
public async Task <UserSetting> Update(UserSetting setting) { ModelValidator.ValidateModelAttributes(setting); Context.UserSettings.Update(setting); await Context.SaveChangesAsync(); return(GetByKey(setting.Id)); }
public async Task <UserNotification> Update(UserNotification notification) { ModelValidator.ValidateModelAttributes(notification); Context.UserNotifications.Update(notification); await Context.SaveChangesAsync(); return(GetByKey(notification.Id)); }
public async Task <CurrencyExchangeRate> Update(CurrencyExchangeRate exchangeRate) { ModelValidator.ValidateModelAttributes(exchangeRate); Context.CurrencyExchangeRates.Update(exchangeRate); await Context.SaveChangesAsync(); return(GetByKey(exchangeRate.Id)); }
public async Task <Category> Update(Category category) { ModelValidator.ValidateModelAttributes(category); Context.Categories.Update(category); await Context.SaveChangesAsync(); return(category); }
public async Task <UserEmailVerificationCode> Update(UserEmailVerificationCode verificationCode) { ModelValidator.ValidateModelAttributes(verificationCode); Context.UserEmailVerificationCodes.Update(verificationCode); await Context.SaveChangesAsync(); return(verificationCode); }
public async Task <Transaction> Update(Transaction transaction) { ModelValidator.ValidateModelAttributes(transaction); Context.Transactions.Update(transaction); await Context.SaveChangesAsync(); return(GetByKey(transaction.Id)); }
public async Task <User> Create(User user) { ModelValidator.ValidateModelAttributes(user); await Context.Users.AddAsync(user); await Context.SaveChangesAsync(); return(GetByEmail(user.Email)); }
public async Task <Wallet> Create(Wallet wallet) { ModelValidator.ValidateModelAttributes(wallet); await Context.Wallets.AddAsync(wallet); await Context.SaveChangesAsync(); return(GetByKey(wallet.Id)); }
public async Task <RegularTransaction> Create(RegularTransaction transaction) { ModelValidator.ValidateModelAttributes(transaction); await Context.RegularTransactions.AddAsync(transaction); await Context.SaveChangesAsync(); return(GetByKey(transaction.Id)); }
public async Task <UserEmailVerificationCode> Create(UserEmailVerificationCode emailVerificationCode) { ModelValidator.ValidateModelAttributes(emailVerificationCode); await Context.UserEmailVerificationCodes.AddAsync(emailVerificationCode); await Context.SaveChangesAsync(); return(emailVerificationCode); }
public Task <BugReport> CreateCase(BugReport bugReport) { ModelValidator.ValidateModelAttributes(bugReport); SalesforceWebService.CreateCase(new SfCase(bugReport)); return(Task.FromResult(bugReport)); }