static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0, 500); //UPCASTING Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0, 200); Account acc3 = new SavingsAccount(1004, "Ana", 0, 0.01); //DONWCASTING BusinessAccount acc4 = (BusinessAccount)acc2; acc4.Loan(100); //BusinessAccount acc5 = (BusinessAccount)acc3; //vai dar o erro InvalidCastException //---> O acc3 apesar de estar numa variavel Account... //ele foi instanciado como um SavingsAccount, e o compilador não consegue fazer essa diferenciação de primeira //portanto é necessario usar a //Palavra reservada 'is' if (acc3 is BusinessAccount) { //BusinessAccount acc5 = (BusinessAccount)acc3; BusinessAccount acc5 = acc3 as BusinessAccount; //Sintaxe alternativa acc5.Loan(200.0); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { //SavingsAccount acc5 = (SavingsAccount)acc3; SavingsAccount acc5 = acc3 as SavingsAccount; //Sintaxe alternativa acc5.UpdateBalance(); Console.WriteLine("Update!"); } }
static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0, 500); // UPCASTING // variavel recebe qualquer tipo de subclasse pertencente a ela Account acc1 = bacc; Account acc2 = new BusinessAccount(); Account acc3 = new SavingsAccount(); // DOWNCASTING BusinessAccount acc4 = (BusinessAccount)acc2; // converter em downcasting acc4.Loan(100); // os métodos só valem se o objeto for do tipo da classe // BusinessAccount acc5 = (BusinessAccount)acc3; // embora não tenha apontado erro no compilador, não é possível a conversão BusinessAccount acc5 = acc3 as BusinessAccount; // outro método de casting if (acc3 is BusinessAccount) { BusinessAccount acc6 = (BusinessAccount)acc3; acc6.Loan(200); Console.WriteLine("Loan"); } if (acc3 is SavingsAccount) { SavingsAccount acc7 = (SavingsAccount)acc3; acc7.UpdateBalance(); Console.WriteLine("Update Balance"); } }
static void Main(string[] args) { Account account = new Account(1001, "Alex", 0.0); BusinessAccount businessAccount = new BusinessAccount(1002, "Maria", 0.0, 500.0); //Upcasting account = businessAccount; Account acc = new BusinessAccount(1003, "bob", 0.0, 200.0); Account acc2 = new SavingsAccount(1004, "Anna", 0.0, 0.01); //Downcasting BusinessAccount bsa = (BusinessAccount)acc; bsa.Loan(100.0); // BusinessAccount acc5 = (BusinessAccount)acc2; if (acc2 is BusinessAccount) { BusinessAccount acc5 = (BusinessAccount)acc2; acc5.Loan(200.0); Console.WriteLine("Loan"); BusinessAccount acc6 = acc2 as BusinessAccount; } if (acc2 is SavingsAccount) { SavingsAccount acc5 = (SavingsAccount)acc2; acc5.UpdateBalance(); Console.WriteLine("Update"); } }
static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0.0, 500.0); //UPCASTING Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200.0); Account acc3 = new SavingsAccount(1004, "Ana", 0.0, 0.01); //DOWNCASTING BusinessAccount acc4 = (BusinessAccount)acc2; acc4.Loan(100.0); //BusinessAccount acc5 = (BusinessAccount)acc3; Erro só na execução SavingsAccount para BusinessAccount //Verificar se acc3 é uma instância de BusinessAccount if (acc3 is BusinessAccount) { //BusinessAccount acc5 = (BusinessAccount)acc3; mesma coisa ↓ BusinessAccount acc5 = acc3 as BusinessAccount; acc5.Loan(200.0); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { SavingsAccount acc5 = (SavingsAccount)acc3; acc5.UpdateBalance(); Console.WriteLine("Update!"); } }
public ClientsDesignData(BusinessAccount serviceProvider, RegionsDesignData regionsDesignData) { var availableServiceTemplates = serviceProvider.ServiceTemplates.Where(st => st.ServiceTemplateLevel == ServiceTemplateLevel.ServiceProviderDefined).ToArray(); InitializeClients(); int clientIndex = 0; foreach (var client in DesignClients) { client.BusinessAccount = serviceProvider; //Add all Service Templates as AvailableServiceTemplates foreach (var availableServiceTemplate in availableServiceTemplates) { var clientServiceTemplate = availableServiceTemplate.MakeChild(ServiceTemplateLevel.ClientDefined); clientServiceTemplate.OwnerClient = client; } //Add Locations to the Client. Must do this before setting up the RecurringServices (they require locations) //This adds 2 locations per client. NOTE: If there are more than 24 clients, this or LocationsDesignData must be updated to have enough locations new LocationsDesignData(client, regionsDesignData.DesignRegions, clientIndex, 1); //Set the default billing location client.Locations.First().IsDefaultBillingLocation = true; //Add RecurringServices new RecurringServicesDesignData(client); clientIndex++; } }
static void Main(string[] args) { Account acc = new Account(1001, "Bruno", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0.0, 500.0); //upcasting Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200.0); Account acc3 = new SavingsAccount(1004, "Anna", 0.0, 0.01); //downcasting BusinessAccount acc4 = (BusinessAccount)acc2; acc4.Loan(100.0); // caso sejam tipos incompativeis fazer o teste if (acc3 is BusinessAccount) { BusinessAccount acc5 = (BusinessAccount)acc3; acc5.Loan(200.0); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { SavingsAccount acc5 = (SavingsAccount)acc3; acc5.UpdateBalance(); Console.WriteLine("Update!"); } }
//GetCompanyBalanceColourRestaurant //GetCompanyBalanceRestaurant public static decimal GetCompanyBalanceRestaurant(this BusinessAccount company) { var totalBills = company.Payments.Where(x => x.PaymentMethodId == (int)PaymentMethodEnum.POSTBILL).Sum(x => x.Total); var paidIn = company.BusinessCorporateAccounts.Where(x => x.PaymentMethodId == (int)PaymentMethodEnum.Cash).Sum(x => x.Amount); return(paidIn - totalBills); }
public EmployeesDesignData(BusinessAccount businessAccount) : this() { if (businessAccount == null) return; foreach (var employee in DesignEmployees) employee.Employer = businessAccount; }
static void Main(string[] args) { Account acc = new Account("Alex", 1001, 0.0); BusinessAccount bacc = new BusinessAccount("Maria", 1002, 0.0, 500.0); // Upcasting Account acc1 = bacc; Account acc2 = new BusinessAccount("Bob", 1003, 0.0, 200.0); Account acc3 = new SavingsAccount("Anna", 1005, 0.0, 0.01); // Downcasting BusinessAccount baac1 = (BusinessAccount)acc2; //acc2.Loan(100.0); Não é possível realizar isso, porque o compilador não sabe que se trata de uma váriavel BusinessAccount, apesar de ter sido feito o Upcasting. baac1.Loan(100.0); // Convertendo, eu consigo realizar essa façanha. // BusinessAccount baac2 = (BusinessAccount)acc3; Internamente será dado um erro, pois essa conversão não é possível (por se tratar de uma váriavel do tipo SavingsAccount. if (acc3 is BusinessAccount) // Isso é usado para verificar, se uma váriavel é uma instância da outra, e não haver erros como esse acima. { // BusinessAccount baac2 = (BusinessAccount)acc3; BusinessAccount baac2 = acc3 as BusinessAccount; // Outra forma de conversão, utilizando no lugar, o as. baac2.Loan(200.0); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { // SavingsAccount acc4 = (SavingsAccount)acc3; SavingsAccount acc4 = acc3 as SavingsAccount; acc4.UpdateBalance(); Console.WriteLine("Update!"); } }
static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0.0, 500.0); // UPCASTING Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200.0); Account acc3 = new SavingsAccount(1004, "Anna", 0.0, 0.01); // DOWNCASTING BusinessAccount acc4 = (BusinessAccount)acc2; acc4.Loan(100.0); // BusinessAccount acc5 = (BusinessAccount)acc3; if (acc3 is BusinessAccount) { //BusinessAccount acc5 = (BusinessAccount)acc3; BusinessAccount acc5 = acc3 as BusinessAccount; acc5.Loan(200.0); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { //SavingsAccount acc5 = (SavingsAccount)acc3; SavingsAccount acc5 = acc3 as SavingsAccount; acc5.UpdateBalance(); Console.WriteLine("Update!"); } }
static void Main(string[] args) { BusinessAccount account = new BusinessAccount(8010, "RafaelSantos", 100.00, 500.0);//´número da conta(Number),Titular(Holder),Saldo da conta(Balance),limite de saque Console.WriteLine(account.Balance); //account.Balance=200.00; Caso colocar essevalor nesse atributo irá dar erro,porque ele não é acessivel para modificalo com protected }
static void Main(string[] args) { // Classe + Subclasse + Protected // A herança reutiliza dados e métodos de outra classe adicionando apenas os // dados e métodos da classe herdeira (subclasse) Account account = new Account(152, "Gustavo", 1800); double amount = 100; account.WithDraw(amount); Console.WriteLine(account.Balance); account.Deposit(amount); Console.WriteLine(account.Balance); BusinessAccount ba = new BusinessAccount(120, "Renan", 1500, 1000); Console.WriteLine(ba.Balance); amount = 1000; ba.Loan(amount); Console.WriteLine(ba.Balance); }
static void Main(string[] args) { BusinessAccount account = new BusinessAccount(8010, "Bob Brow", 100.0, 500.0); Console.WriteLine(account.Balance); //account.Balance = 200.0; }
public static void CreateBusiness() { try { Console.WriteLine("enter your customer ID"); int id = Convert.ToInt32(Console.ReadLine()); var cust = CustomerBL.GetCust(id); Console.WriteLine("enter your new business account name"); var name = Console.ReadLine(); Console.WriteLine("enter checking your account amount"); double amount = Convert.ToDouble(Console.ReadLine()); BusinessAccount acc = new BusinessAccount(name, amount); CustomerBL.AddBusiness(cust, acc); Console.WriteLine($"Business Account of {acc.Name} is created"); } catch (Exception ex) { Console.WriteLine("registeration fail, please try again"); } }
//StandingCheckAndSet public void StandingCheckAndSet(User user) { bool goodStanding = true; foreach (IAccount acc in user.Accounts) { if (acc is BusinessAccount) { BusinessAccount biz = (BusinessAccount)acc; if (biz.CurrentBalance < 0) { ((BusinessAccount)acc).IsOverdraft = true; ((BusinessAccount)acc).OverDraftAmount = ((BusinessAccount)acc).CurrentBalance; goodStanding = false; } } if (acc is LoanAccount) { LoanAccount loan = (LoanAccount)acc; if (Math.Abs(loan.CurrentBalance - loan.MaximumBalance) < double.Epsilon) { goodStanding = false; } } } user.GoodStanding = goodStanding; UserDAL userDAL = new UserDAL(); userDAL.UpdateUserDAL(user); }
public void WithDraw(Account account, MyClientDbContext _context, double amount) { double previous = account.AccountBalance; if (account.AccountType == "Business") { BusinessAccount ba = new BusinessAccount(); ba.WithDraw(account, amount); } else if (account.AccountType == "Checking") { CheckingAccount ca = new CheckingAccount(); ca.WithDraw(account, amount); } else if (account.AccountType == "Loan") { Loan loan = new Loan(); loan.WithDraw(account, amount); } else if (account.AccountType == "Term") { TermDeposit term = new TermDeposit(); term.WithDraw(account, amount); } _context.Accounts.Update(account); _context.SaveChanges(); createTransaction(account, previous, account.AccountBalance, amount, "WithDraw", _context); }
public void Transfer(Account account, Account account2, MyClientDbContext _context, double amount) { if (account.AccountNumber == account2.AccountNumber) { Console.WriteLine("Can't Transfer to the same account"); } else { if (account.AccountType.Equals("Checking") && (account2.AccountType.Equals("Checking") || account2.AccountType.Equals("Business"))) { account.WithDraw(account, amount); account2.Deposit(account2, amount); } else if (account.AccountType.Equals("Business") && (account2.AccountType.Equals("Business") || account2.AccountType.Equals("Checking"))) { BusinessAccount ba = new BusinessAccount(); ba.WithDraw(account, amount); account2.Deposit(account2, amount); } } transferTransaction(account, account2, account.AccountBalance, account2.AccountBalance, amount, "Transfer", _context); _context.Accounts.Update(account); _context.Accounts.Update(account2); _context.SaveChanges(); }
static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0.0, 500.0); //Upcasting - da subclasse pra superclasse //Perfeitamete possivel pois é uma relação de é um //BusinessAccount é um Account //Não é possivel usar as funções das outras classes na superclasse Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200); Account acc3 = new SavingsAccount(1004, "Ana", 0.0, 0.1); //----------------------------------------------------------------- //DOWNCASTING - Da superclasse pra subclasse //precisa do castinng explicito BusinessAccount acc4 = acc2 as BusinessAccount; //SINTAXE ALTERNATICA PARA O CASTING //UMA OPERAÇÃO INSEGURA, PRECISA TESTAR ANTES DE CONVERTER if (acc3 is BusinessAccount) { BusinessAccount acc5 = (BusinessAccount)acc3; acc5.Loan(200); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { SavingsAccount acc5 = acc3 as SavingsAccount; acc5.UpdateBalace(); Console.WriteLine("Update"); } //----------------------------------------------------- }
static void Main(string[] args) { BusinessAccount account = new BusinessAccount(8010, "Bob champs", 100.00, 500.0); //account.Balance = 200.00 não é possível pelo modificador de acesso! Console.WriteLine(account); }
static void Main(string[] args) { Account acc = new Account(1001, "Rogerio", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0.0, 500.0); // UPCASTING Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Joaquim", 0.0, 200.0); Account acc3 = new SavingsAccount(1004, "Gabriel", 0.0, 0.01); // DOWNCASTING BusinessAccount bacc4 = (BusinessAccount)acc2; bacc4.Loan(100.00); if (acc3 is BusinessAccount) { BusinessAccount acc5 = (BusinessAccount)acc3; acc5.Loan(200.00); Console.WriteLine("Loan !"); } if (acc3 is SavingsAccount) { // SavingsAccount acc5 = (SavingsAccount)acc3; => Funciona SavingsAccount acc5 = acc3 as SavingsAccount; // Nova forma de fazer o casting acc5.UpdateBalance(); Console.WriteLine("Update !"); } }
public static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0, 500); // UPCASTING Account acc1 = bacc; // It works, because BusinessAccount is an Account Account acc2 = new BusinessAccount(1003, "Steven", 4000, 200); Account acc3 = new SavingsAccount(1004, "Ana", 0, 0.01); // DOWNCASTING (for this, it's important verify the object type if (acc3 is BusinessAccount) { BusinessAccount acc4 = acc3 as BusinessAccount; acc4.Loan(100); } else if (acc3 is SavingsAccount) { SavingsAccount acc5 = acc3 as SavingsAccount; acc5.UpdateBalance(); } Console.ReadKey(); }
public static void RunAccountUpCastingDowncasting() { Account acc = new Account(1001, "Alex", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0.0, 500.0); //UPCASTING Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200.0); Account acc3 = new SavingsAccount(1004, "Anna", 0.0, 0.01); //DOWNCASTING BusinessAccount acc4 = (BusinessAccount)acc2; if (acc3 is BusinessAccount) { //BusinessAccount acc5 = (BusinessAccount)acc3; BusinessAccount acc5 = acc3 as BusinessAccount; acc5.Loan(200.0); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { SavingsAccount acc5 = (SavingsAccount)acc3; acc5.UpdateBalance(); Console.WriteLine("Update!"); } }
static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "maria", 0.0, 500.0); //Uppcasting Account acc1 = bacc; // eu posso fazer essa atribuição porque o account e o businessAccunt são naturalmente account, podendo assim receber. Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200.0); Account acc3 = new SavingAccount(1004, "Ana", 0, 0.01); //Downcasting BusinessAccount acc4 = (BusinessAccount)acc2; acc4.Loan(100); //BusinessAccount acc5 = (BusinessAccount)acc3; if (acc3 is BusinessAccount) { //BusinessAccount acc5 = (BusinessAccount)acc3; BusinessAccount acc5 = acc3 as BusinessAccount; acc5.Loan(200.0); Console.WriteLine("Loan"); } if (acc3 is SavingAccount) { //SavingAccount acc5 = (SavingAccount)acc3; SavingAccount acc5 = acc3 as SavingAccount; acc5.UpdateBalance(); Console.WriteLine("Update"); } }
public void PayLoanInstallment(Account account, Account account2, MyClientDbContext _context, double amount) { double previous = account.AccountBalance; if (account.AccountType == "Loan" && account2.AccountType == "Checking") { double prev = account2.AccountBalance; CheckingAccount ca = new CheckingAccount(); ca.WithDraw(account2, amount); if (prev > account2.AccountBalance) { Loan loan = new Loan(); loan.payLoanInstallment(account, amount); } } else if (account.AccountType == "Loan" && account2.AccountType == "Business") { BusinessAccount ba = new BusinessAccount(); ba.WithDraw(account2, amount); Loan loan = new Loan(); loan.payLoanInstallment(account, amount); } createTransaction(account, previous, account.AccountBalance, amount, "PayLoan", _context); if (account.AccountBalance == 0) { account.Activated = false; } _context.Accounts.Update(account); _context.SaveChanges(); }
static void Main(string[] args) { Console.WriteLine("Exemplo 3 sacando + taxa na conta superclasse onde a subclasse herda mais qualquer coisa : "); Console.WriteLine("sobreposição / subscrita usa na função superclasse a prefix virtual e na subclasse override"); Console.WriteLine("usando base pra Herda da Superclasse os atributos "); Console.WriteLine(); Account acc1 = new Account(1001, "Gilvan", 200.0); BusinessAccount acc2 = new BusinessAccount(1002, "Lucas", 200.00, 500.0); SavingsAccount acc3 = new SavingsAccount(1003, "Matheus", 200.0, 0.01); Console.WriteLine("na superclasse usa no metodo o prefixo virtual"); Console.WriteLine("Saldo Account : " + acc1.Balance.ToString("F2", CultureInfo.InvariantCulture)); acc1.Withdraw(10.0); Console.WriteLine("Saldo atualizado: " + acc1.Balance.ToString("F2", CultureInfo.InvariantCulture)); Console.WriteLine(); Console.WriteLine("na subclasse usa no metodo o prefixo override + base ele herda da superclasse desconta 2.00"); Console.WriteLine("Saldo BusinessAccount : " + acc2.Balance.ToString("F2", CultureInfo.InvariantCulture)); acc2.Withdraw(10.0); Console.WriteLine("Saldo atualizado: " + acc2.Balance.ToString("F2", CultureInfo.InvariantCulture)); Console.WriteLine(); Console.WriteLine("na subclasse usa no metodo o prefixo override"); Console.WriteLine("Saldo SavingsAccount : " + acc3.Balance.ToString("F2", CultureInfo.InvariantCulture)); acc3.Withdraw(10.0); Console.WriteLine("Saldo atualizado: " + acc3.Balance.ToString("F2", CultureInfo.InvariantCulture)); Console.WriteLine(); }
static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "Maria", 0.0, 500.0); //UPCASTING Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200.0); Account acc3 = new SavingsAccount(1004, "Anna", 0.0, 0.01); //DOWNCASTING BusinessAccount acc4 = acc2 as BusinessAccount; acc4.Loan(100.0); //acc2.Loan(100.0); não dá para fazer a implementação, pois não foi feito o DOWNCASTING. //BusinessAccount acc5 = acc3 as BusinessAccount; ocorre erro, pois acc3 SavingsAccount. if (acc3 is BusinessAccount) { BusinessAccount acc5 = acc3 as BusinessAccount; acc5.Loan(200.0); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { SavingsAccount acc5 = acc3 as SavingsAccount; acc5.UpdateBalance(); Console.WriteLine("Update!"); } }
static void BusinessAction(BusinessAccount acc, string actionType) { switch (actionType.ToLower()) { case "deposit": Console.WriteLine("enter amount"); double deposit = Convert.ToInt32(Console.ReadLine()); acc.Deposit(deposit); break; case "withdraw": Console.WriteLine("enter amount"); double withdraw = Convert.ToInt32(Console.ReadLine()); acc.Withdraw(withdraw); break; case "transfer": Console.WriteLine("enter 2nd customer id "); int custid = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter 2nd account id"); int accId = Convert.ToInt32(Console.ReadLine()); var acc2 = CustomerBL.GetAccount(custid, accId); double transfer = Convert.ToInt32(Console.ReadLine()); acc.Transfer(acc, acc2, transfer); break; default: break; } }
public static void OpenSelectedAccount(Customer customer) { Console.WriteLine("What kind of account you want to open?" + "\nex: checking account, business account, loan account, term deposit."); //Account a = new CheckingAccount(); string act = Console.ReadLine(); if (act.Equals("Checking account", StringComparison.OrdinalIgnoreCase)) { CheckingAccount ck = new CheckingAccount(); OpenAccount(customer, ck); ck.PrintInfor(); } else if (act.Equals("Business account", StringComparison.OrdinalIgnoreCase)) { BusinessAccount ba = new BusinessAccount(); OpenAccount(customer, ba); ba.PrintInfor(); } else if (act.Equals("Term deposit", StringComparison.OrdinalIgnoreCase)) { TermDeposit tm = new TermDeposit(); OpenAccount(customer, tm); tm.PrintInfor(); } else { Console.WriteLine("Invalid account!"); } }
static void Main(string[] args) { Account acc = new Account(1001, "Alex", 0.0); BusinessAccount bacc = new BusinessAccount(1002, "Maria,", 0.00, 500); //UPCASTING Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200.0); Account acc3 = new SavingsAccount(1004, "Ana", 0.0, 0.1); //DOWNCASTING BusinessAccount acc4 = (BusinessAccount)acc2; //BusinessAccount acc5 = (BusinessAccount)acc3; //acc3 for uma instância de businessAccount if (acc3 is BusinessAccount) { BusinessAccount acc5 = (BusinessAccount)acc3; //acc3 as BusinessAccount } }
public async Task <IActionResult> Deposit(int id, BusinessAccount businessAcct) { if (id != businessAcct.Id) { return(NotFound()); } var currAcct = await _context.BusinessAccounts.FirstOrDefaultAsync(m => m.Id == id); if (ModelState.IsValid) { try { decimal newBalance = 0; if (CheckDepositAmount(currAcct, businessAcct)) //check if deposit amount positive { return(View(currAcct)); } if (currAcct.Overdraft > 0) { if (businessAcct.Balance > currAcct.Overdraft) // pay off the entire overdraft and deposit whats left { newBalance = businessAcct.Balance - currAcct.Overdraft; AddTransaction(currAcct, currAcct.Overdraft, "Overdraft Pay"); currAcct.Overdraft = 0M; AddTransaction(currAcct, newBalance, "Deposit"); } else if (businessAcct.Balance < currAcct.Overdraft) { currAcct.Overdraft -= businessAcct.Balance; AddTransaction(currAcct, businessAcct.Balance, "Overdraft Pay"); } } else { newBalance = currAcct.Balance + businessAcct.Balance; AddTransaction(currAcct, businessAcct.Balance, "Deposit"); } currAcct.Balance = newBalance; //_context.Update(checkingAccount); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BusinessAccountExists(businessAcct.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(currAcct)); }
static void ProgramaQuatro() { Account acc = new BusinessAccount(1001, "Alex", 0.0, 200.0); BusinessAccount bacc = new BusinessAccount(1002, "Bia", 0.0, 500.0); //UPCASTING Account acc1 = bacc; Account acc2 = new BusinessAccount(1003, "Bob", 0.0, 200.0); Account acc3 = new SavingsAccount(1004, "Ana", 0.0, 0.01); //DOWNCASTING -- OPERAÇÃO INSEGURA -- TESTAR BusinessAccount acc4 = (BusinessAccount)acc2; acc4.Loan(200.0); //BusinessAccount acc5 = (BusinessAccount) acc3; //<< ISSO NÃO É POSSÍVEL O COMPILADOR ENTENDER //Usando operador " is " para testar if (acc3 is BusinessAccount) { //BusinessAccount acc5 = (BusinessAccount)acc3; BusinessAccount acc5 = acc3 as BusinessAccount; acc5.Loan(200.0); Console.WriteLine("Loan!"); } if (acc3 is SavingsAccount) { //SavingsAccount acc5 = (SavingsAccount)acc3; SavingsAccount acc5 = acc3 as SavingsAccount; acc5.UpdateBalance(); Console.WriteLine("Update"); } }
static void Main(string[] args) { BusinessAccount account = new BusinessAccount(8010, "Bob Brown", 100.0, 500.0); //Balance é uma variável protected. Por isso a linha abaixo não funciona. //account.Balance = 200.0; }
public ServicesDesignData(BusinessAccount serviceProvider, Client client, IEnumerable<ServiceTemplate> serviceTemplates) { _serviceTemplates = serviceTemplates; _serviceProvider = serviceProvider; _client = client; InitializeServices(); }
/// <summary> /// Initializes a new instance of the <see cref="RoutesDesignData"/> class. /// </summary> /// <param name="ownerBusinessAccount">The owner business account.</param> /// <param name="clientsDesignData">The clients design data.</param> /// <param name="vehiclesDesignData">The vehicles design data.</param> /// <param name="employeesDesignData">The employees design data.</param> public RoutesDesignData(BusinessAccount ownerBusinessAccount, ClientsDesignData clientsDesignData, VehiclesDesignData vehiclesDesignData, EmployeesDesignData employeesDesignData) { _ownerBusinessAccount = ownerBusinessAccount; _clientsDesignData = clientsDesignData; _vehiclesDesignData = vehiclesDesignData; _employeesDesignData = employeesDesignData; InitializeRoutes(ownerBusinessAccount); }
/// <summary> /// Create routes from yesterday until tomorrow for the current service provider. /// </summary> private void InitializeRoutes(BusinessAccount ownerBusinessAccount) { var date = DateTime.UtcNow.Date; DesignRoutes = new List<Route>(); var serviceTemplates = _ownerBusinessAccount.ServiceTemplates.Where(st => st.ServiceTemplateLevel == ServiceTemplateLevel.ServiceProviderDefined).ToArray(); //Create three routes for yesterday for (int i = 0; i <= 3; i++) CreateRoute(date.AddDays(-1), serviceTemplates.RandomItem(), ownerBusinessAccount, i); //Create three routes for today for (int i = 0; i <= 3; i++) CreateRoute(date, serviceTemplates.RandomItem(), ownerBusinessAccount, i); //Create three routes for tomorrow for (int i = 0; i <= 3; i++) CreateRoute(date.AddDays(1), serviceTemplates.RandomItem(), ownerBusinessAccount, i); }
public static Role SetupServiceProviderRole(BusinessAccount ownerParty, RoleType roleType) { var role = new Role { OwnerBusinessAccount = ownerParty, RoleType = roleType }; if (roleType == RoleType.Administrator) { role.Name = "Administrator"; foreach (var block in BlocksData.RegularBlocks.Union(BlocksData.MobileBlocks)) role.Blocks.Add(block); } else if (roleType == RoleType.Regular) { role.Name = "Regular"; foreach (var block in BlocksData.RegularBlocks.Union(BlocksData.MobileBlocks)) role.Blocks.Add(block); } else if (roleType == RoleType.Mobile) { role.Name = "Mobile"; foreach (var block in BlocksData.MobileBlocks) role.Blocks.Add(block); } return role; }
public VehiclesDesignData(BusinessAccount ownerParty) { _ownerParty = ownerParty; InitializeVehicles(); _vehicleMaintenanceDesignData = new VehicleMaintenanceDesignData(this); }
public void Initialize() { _bankAccount = new BusinessAccount(); }
private void InitializeBusinessAccounts() { GotGrease = new BusinessAccount { Id = new Guid("8528E50D-E2B9-4779-9B29-759DBEA53B61"), Name = "GotGrease?", QuickBooksEnabled = true, MaxRoutes = 10, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; ABCouriers = new BusinessAccount { Id = new Guid("3281B373-101F-415A-B708-14B9BA95A618"), Name = "AB Couriers", QuickBooksEnabled = true, MaxRoutes = 10, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; GenericOilCollector = new BusinessAccount { Id = new Guid("62047896-B2A1-49E4-BA10-72F0667B1DB0"), Name = "Generic Oil Collector", QuickBooksEnabled = true, MaxRoutes = 10, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; GenericBiodiesel = new BusinessAccount { Id = new Guid("BEB79E47-9B39-4730-BFEB-D15986438DAA"), Name = "Generic Biodiesel", QuickBooksEnabled = true, MaxRoutes = 10, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; DesignServiceProviders = new List<BusinessAccount> { GotGrease, ABCouriers, GenericOilCollector, GenericBiodiesel }; //Add ServiceTemplates foreach (var serviceProvider in new[] { GotGrease, ABCouriers, GenericOilCollector, GenericBiodiesel }) { //Add task statuses var defaultStatuses = TaskStatuses.CreateDefaultTaskStatuses(); foreach (var taskStatus in defaultStatuses) serviceProvider.TaskStatuses.Add(taskStatus); //Add depot serviceProvider.Depots.Add(new Location { Name = "Depot", AddressLineOne = "1305 Cumberland Ave", AdminDistrictTwo = "West Lafayette", AdminDistrictOne = "IN", PostalCode = "47906", CountryCode = "US", BusinessAccount = serviceProvider, Latitude = (decimal?)40.460335, Longitude = (decimal?)(-86.929840), CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }); //Choose the right set of ServiceTemplates var serviceTemplates = serviceProvider == ABCouriers ? ServiceTemplatesDesignData.SameDayDeliveryCompanyServiceTemplates : ServiceTemplatesDesignData.OilGreaseCompanyServiceTemplates; foreach (var serviceTemplate in serviceTemplates) { var serviceTemplateChild = serviceTemplate.MakeChild(ServiceTemplateLevel.ServiceProviderDefined); serviceTemplateChild.OwnerServiceProvider = serviceProvider; } } }
/// <summary> /// Creates a route from a service template and date. Uses a random route name. /// </summary> private void CreateRoute(DateTime date, ServiceTemplate serviceTemplate, BusinessAccount ownerBusinessAccount, int clientIndex) { var newRoute = new Route { Id = Guid.NewGuid(), Name = _routeNames.RandomItem(), Date = date.Date, RouteType = serviceTemplate.Name, OwnerBusinessAccount = ownerBusinessAccount, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; //Add employees to the Route newRoute.Employees.Add(_employeesDesignData.DesignEmployees.FirstOrDefault(e => e.FirstName == "Jon")); //Add vehicles to the Route newRoute.Vehicles.Add(_vehiclesDesignData.DesignVehicles.RandomItem()); var orderInRoute = 1; var startingClientIndex = clientIndex * 6; //Create Services and RouteTasks, add them to the Route for (var i = startingClientIndex; i <= (startingClientIndex + 5); i++) { //Prevents you from trying to add a client that doesnt exist in Design Data if (i > _clientsDesignData.DesignClients.Count()) break; var currentClient = _clientsDesignData.DesignClients.ElementAt(i); //Take the first location from the client var currentLocation = currentClient.Locations.ElementAt(0); var newService = new Service { ServiceDate = newRoute.Date, ServiceTemplate = serviceTemplate.MakeChild(ServiceTemplateLevel.ServiceDefined), Client = currentClient, ServiceProvider = ownerBusinessAccount, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; newService.ServiceTemplate.SetDestination(currentLocation); var routeTask = new RouteTask { OrderInRouteDestination = 1, Date = newRoute.Date, Location = currentClient.Locations.ElementAt(0), Client = currentClient, Name = newRoute.RouteType, EstimatedDuration = new TimeSpan(0, _random.Next(25), 0), OwnerBusinessAccount = ownerBusinessAccount, Service = newService, TaskStatus = ownerBusinessAccount.TaskStatuses.FirstOrDefault(ts => ts.DefaultTypeInt != null && ts.DefaultTypeInt == ((int)StatusDetail.RoutedDefault)), CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; var routeDestination = new RouteDestination { OrderInRoute = orderInRoute, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; routeDestination.RouteTasks.Add(routeTask); newRoute.RouteDestinations.Add(routeDestination); orderInRoute++; } DesignRoutes.Add(newRoute); }