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); } }
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; } }