예제 #1
0
 public string AddCustomerToAccount(Guid accountId, CustomerDto customerDto)
 {
     try
     {
         Guid personId = customerDto.PersonId;
         AccountRepository repository = new AccountRepository();
         Person person = repository.ActiveContext.Persons.Where(p => p.Id == personId).FirstOrDefault();
         if (person == null) return ("the person id is invalid and customer can't be find");
         Account account =
             repository.ActiveContext.BankAccounts.OfType<Account>()
                       .Include("customers.Person")
                       .Where(a => a.Id == accountId)
                       .FirstOrDefault();
         if (account == null) return "account id is invalid and can not be find";
         if (!account.ContainCustomer(personId))
         {
             Customer customer = Customer.CreateCustomer(person, customerDto.No, customerDto.Portion);
             account.Customers = new Collection<Customer>();
             account.Customers.Add(customer);
             repository.ActiveContext.SaveChanges();
             return "customer added successfully";
         }
         return "customer was there in database";
     }
     catch (Exception fException)
     {
         return fException.Message;
     }
 }
예제 #2
0
 public string AddCustomerToAccount(Guid accountId, Guid id)
 {
     CustomerDto customerDto = new CustomerDto();
       customerDto.PersonId = id;
       customerDto.No = "4";
       customerDto.Portion = 1;
       PersonAccountService personAccountService = new PersonAccountService();
       personAccountService.AddCustomerToAccount(accountId, customerDto);
       return "completed";
 }