public Account AddAccount(Account account, bool isRoot=false)
        {
            using (UnitOfWork.Start())
            {
                using (accountService = new EntityService<Account>(new Repository<Account>()))
                {
                    if (isRoot)
                    {
                        account.Parent = null;
                    }
                    var olds = accountService.FindByProperty("AccountName", account.AccountName.Trim());
                    if (olds != null && olds.Count > 0)
                    {
                        throw new Exception("Account {0}- {1} already exists.");
                    }
                    else {
                        return accountService.Save(account);
                    }

                }
            }

        }
Exemple #2
0
        static void Main(string[] args)
        {


            using (UnitOfWork.Start())
            {
                //  BuildSchema(UnitOfWork.Configuration);



                var _AccountRepository = new Repository<Account>();
                EntityService<Account> service = new EntityService<Account>(_AccountRepository);
                service.Saved += Service_Saved;

                var tableAcc = new Account
                {
                    AccountCode = 2,
                    IsActive = true,
                    AccountName = "Sales",
                    TrialBalance = 0,
                    Description = "Sales account",
                    //  Parent = parent
                };


             //   service.Save(tableAcc);
               
                var accounts = service.FindAll("Id");
                foreach (var account in accounts)
                {
                    if (account.Parent == null)
                        System.Console.WriteLine(account.ToString());
                }
                System.Console.ReadKey();
            }
        }