Exemplo n.º 1
0
 public string AddLawyerToAccount(Guid accountId, LawyerDto lawyerDto)
 {
     try
     {
         Guid personId = lawyerDto.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 person can't be find");
         }
         Account account =
             repository.ActiveContext.BankAccounts.OfType <Account>()
             .Include("Lawyers.Person")
             .FirstOrDefault(a => a.Id == accountId);
         if (account == null)
         {
             return("account id is invalid and lawyer can't be added");
         }
         if (!account.ContainLawyer(personId))
         {
             Lawyer lawyer = Lawyer.CreateLawyer(person, lawyerDto.StartDate);
             account.Lawyers = new Collection <Lawyer>();
             account.Lawyers.Add(lawyer);
             repository.ActiveContext.SaveChanges();
             return("lawyer added successfully");
         }
         return("lawyer was there and can't be recreated");
     }
     catch (Exception fException)
     {
         return(fException.Message);
     }
 }
Exemplo n.º 2
0
        public void Add_Single_Person_As_Customer_And_Lawyer_2()
        {
            var person   = CreatePerson();
            var lawyer   = Lawyer.CreateLawyer(person, new DateTime(2012, 12, 20));
            var customer = Customer.CreateCustomer(person, "3", 1);

            var account = AccountTest.CreateAccount();

            account.Lawyers.Add(lawyer);
            account.Customers.Add(customer);
            //     Assert.True(this.anotherContext.Accounts.SelectMany(o => o.Lawyers).Distinct().Count() == 1);
            //   Assert.True(this.anotherContext.Accounts.SelectMany(o => o.Customers).Count() == 1);
            // Assert.True(this.anotherContext.Accounts.Count() == 1);
        }