public async Task <bool> Transfer(string senderAccountNumber, string recipientAccountNumber, int amount) { ClientAccountModel sender = await _bContext.ClientAccountModel.AsNoTracking() .Where(d => d.AccountNumber == senderAccountNumber) .Select(d => d) .FirstOrDefaultAsync(); ClientAccountModel recipient = await _bContext.ClientAccountModel.AsNoTracking() .Where(d => d.AccountNumber == recipientAccountNumber) .Select(d => d) .FirstOrDefaultAsync(); if (sender.Money - amount > 0) { sender.Money -= amount; recipient.Money += amount; } else { return(false); } await _bContext.AddAsync(sender); await _bContext.AddAsync(recipient); if (await _bContext.SaveChangesAsync() == 1) { return(true); } return(false); }
public async Task <bool> RemoveClient(int clientId) { ClientModel clientModel = new ClientModel(); ClientAccountModel accountModel = new ClientAccountModel(); clientModel = await _bContext.ClientModel.AsNoTracking() .Where(d => d.Id == clientId) .Select(d => d) .FirstOrDefaultAsync(); accountModel = await _bContext.ClientAccountModel.AsNoTracking() .Where(d => d.ClientId == clientId) .Select(d => d) .FirstOrDefaultAsync(); clientModel.Login = null; clientModel.Email = null; clientModel.PhoneNumber = null; clientModel.PasswordHash = null; clientModel.ConfirmedEmail = false; clientModel.ConfirmedPhoneNumber = false; accountModel.IsActive = false; await _bContext.AddAsync(clientModel); await _bContext.AddAsync(accountModel); if (await _bContext.SaveChangesAsync() == 1) { return(true); } return(false); }
public static RezervationModel ToModel(this Rezervation dbRezervation, ClientAccountModel clientAccountModel) { var model = dbRezervation.ToModel(); model.ClientAccount = clientAccountModel; return(model); }
public async Task GetClientAccountTest() { ClientAccountModel expected = CreateClientAccountModel(); SetupAccountServiceGetClientAccountMock(Token, expected); var actual = (JsonResult)await accountApiController.GetClientAccount(Token); Assert.AreEqual(expected, actual.Value); }
public async Task <bool> AddClient(string firstName, string lastName, string email, string phoneNumber) { Random r = new Random(); ClientModel clientModel = new ClientModel() { Id = await _bContext.ClientModel.AsNoTracking() .Select(d => d.Id) .LastAsync() + 1, FirstName = firstName, LastName = lastName, Login = firstName + lastName + r.Next(10, 99), PhoneNumber = phoneNumber, ConfirmedPhoneNumber = true, Email = email, ConfirmedEmail = true, PasswordHash = Hash("1234aA!") }; StringBuilder accountNumber = new StringBuilder(); for (int i = 0; i < 18; i++) { accountNumber.Append(r.Next(0, 9)); } ClientAccountModel clientAccount = new ClientAccountModel() { Id = await _bContext.ClientAccountModel.AsNoTracking() .Select(d => d.Id) .LastAsync() + 1, ClientId = clientModel.Id, AccountNumber = accountNumber.ToString(), Money = 0, IsActive = true }; await _bContext.AddAsync(clientModel); await _bContext.AddAsync(clientAccount); if (await _bContext.SaveChangesAsync() == 1) { return(true); } return(false); }
public async Task <bool> Payment(string clientAccountNumber, int amount) { ClientAccountModel money = await _bContext.ClientAccountModel.AsNoTracking() .Where(d => d.AccountNumber == clientAccountNumber) .Select(d => d) .FirstOrDefaultAsync(); money.Money += amount; await _bContext.AddAsync(money); if (await _bContext.SaveChangesAsync() == 1) { return(true); } return(false); }
public async Task <AuthorizationRequestModel> GetClientAccountAsync(string token) { SessionData session = await sessionRepository.GetByTokenAsync(token); User user = await applicationUserRepository.FindByIdAsync(session.UserId); ClientData client = clientRepository.FindByUser(user); var account = new ClientAccountModel() { Email = user.Email, Passport = client.Passport, Telephone = client.Telephone, Name = client.Name, Surname = client.Surname, PhotoPath = client.PhotoPath, Role = applicationRoleRepository.Get(user.RoleId).Name, CreditCards = await creditCardRepository.GetByClientAsync(client.Id) }; return(account); }
private void SetupAccountServiceGetClientAccountMock(string token, ClientAccountModel clientAccountModel) => accountServiceMock .Setup(service => service.GetClientAccountAsync(token)) .ReturnsAsync(clientAccountModel);