//private AccountYear GetYearById(int orgId, int yearId = 0)
        //{
        //    AccountYear year = null;
        //    if (yearId > 0)
        //        year = _yearRepository.GetById(yearId);

        //    if (year == null)
        //        year = new AccountYear { OrgId = org.Id };
        //    org.Year = year;
        //    return org;
        //}

        public int Add(Organization org)
        {
            org.CreatedAt = DateTime.Now;
            using (var con = _db.GetConnection())
            {
                using (var tran = con.BeginTransaction())
                {
                    int?addressId = _addressRepository.Save(org.Address, con, tran);
                    int?contactId = _contactRepository.Save(org.Contact, con, tran);
                    org.AddressId = addressId;
                    org.ContactId = contactId;
                    int orgId = Convert.ToInt32(con.Insert(org, tran));
                    org.Id = orgId;

                    // Accounting Year
                    int yearId = _yearRepository.Add(orgId, org.Year, con, tran);
                    UpdateActiveYearId(orgId, yearId, con, tran);

                    // Seed: Org
                    SeedOrg(orgId, con, tran);
                    // Seed : Year
                    SeedYearSerialNumbers(yearId, con, tran);

                    tran.Commit();
                    return(orgId);
                }
            }
        }
        public virtual bool Save(int ledgerId, TEntity entity, IDbConnection con, IDbTransaction tran)
        {
            if (ledgerId <= 0)
            {
                return(false);
            }

            if (entity == null)
            {
                return(true);
            }

            entity.LedgerId = ledgerId;
            bool found = con.Any <TEntity>(b => b.LedgerId == ledgerId);

            // Insert
            if (!found)
            {
                // No data, skip
                if (entity.IsEmpty())
                {
                    return(true);
                }

                // Insert
                int?addressId = _addressRepository.Save(entity.Address, con, tran);
                int?contactId = _contactRepository.Save(entity.Contact, con, tran);
                entity.AddressId = addressId;
                entity.ContactId = contactId;
                int entityId = Convert.ToInt32(con.Insert(entity, tran));
                return(entityId > 0);
            }
            // Update/Delete
            else
            {
                // Delete
                if (entity.IsEmpty())
                {
                    return(Remove(ledgerId, con, tran));
                }

                // Update
                int?addressId = _addressRepository.Save(entity.Address, con, tran);
                int?contactId = _contactRepository.Save(entity.Contact, con, tran);
                entity.AddressId = addressId;
                entity.ContactId = contactId;
                return(con.Update(entity, tran));
            }
        }