예제 #1
0
 public void TestMethod1()
 {
     using (var context = new ApplicationContext(connectionString))
     {
         var sysAdmins = context.SecurityRoles.ToList();
     }
 }
예제 #2
0
 public OverController()
 {
     var db = new ApplicationContext();
     var unitOfWork = new UnitOfWork(db);
     _overDetailService = new OverDetailService(new Repository<OverDetail>(db, unitOfWork));
     _overService= new OverService(new Repository<Over>(db, unitOfWork));
 }
예제 #3
0
        public void TestMethod1()
        {
            using (var context = new ApplicationContext(connectionString))
            {
                //var account = context.Accounts.Where(a => a.AccountCode == "10111").FirstOrDefault();
                //var balance = account.GetBalance();

                //var gl = context.GeneralLedgerHeaders.Where(g => g.Id == 86).FirstOrDefault();
                //bool isEqual = gl.ValidateAccountingEquation();
                //isEqual = gl.ValidateAssetsEqualsEquities();
                //isEqual = gl.ValidateLiabilitiesEqualsExpenses();
                //isEqual = gl.ValidateAssetsEqualsRevenues();
            }
        }
예제 #4
0
        public static List<AuditLog> GetChangesForAuditLog(DbEntityEntry dbEntry, string username, ApplicationContext context)
        {
            _context = context;
            var result = new List<AuditLog>();

            // Get the Table() attribute, if one exists
            Type entryType = dbEntry.Entity.GetType();

            TableAttribute tableAttr = entryType.GetCustomAttributes(typeof(TableAttribute), false).SingleOrDefault() as TableAttribute;

            if (tableAttr == null)
            {
                tableAttr = entryType.BaseType.GetCustomAttributes(typeof(TableAttribute), false).SingleOrDefault() as TableAttribute;
            }

            // Get table name (if it has a Table attribute, use that, otherwise get the pluralized name)
            string tableName = tableAttr != null ? tableAttr.Name : dbEntry.Entity.GetType().Name;

            if (tableName.IndexOf("_") > 0)
                tableName = tableName.Substring(0, tableName.IndexOf("_"));

            FillAuditableEntityAndAttributes(tableName);

            try
            {
                // Get primary key value (If you have more than one key column, this will need to be adjusted)
                string keyName = dbEntry.Entity.GetType().GetProperties().Single(p => p.GetCustomAttributes(typeof(KeyAttribute), false).Count() > 0).Name;

                DateTime changeTime = DateTime.UtcNow;

                if (dbEntry.State == System.Data.Entity.EntityState.Added)
                {
                    //For Inserts, just add the whole record
                    if (IsEntityAuditable(tableName))
                    {
                        string dbEntryObject = ObjectFieldsValues(dbEntry);

                        result.Add(CreateAuditLog(username,
                            changeTime,
                            AuditEventTypes.Added,
                            tableName,
                            dbEntry.CurrentValues.GetValue<object>(keyName).ToString(),
                            string.Empty,
                            string.Empty,
                            dbEntryObject));

                        addedEntities.Add(new KeyValuePair<DateTime, DbEntityEntry>(changeTime, dbEntry));
                    }
                }
                else if (dbEntry.State == System.Data.Entity.EntityState.Deleted)
                {
                    if (IsEntityAuditable(tableName))
                    {
                        string dbEntryObject = ObjectFieldsValues(dbEntry);

                        result.Add(CreateAuditLog(username,
                        changeTime,
                        AuditEventTypes.Deleted,
                        tableName,
                        dbEntry.CurrentValues.GetValue<object>(keyName).ToString(),
                        string.Empty,
                        string.Empty,
                        dbEntryObject));
                    }
                }
                else if (dbEntry.State == System.Data.Entity.EntityState.Modified)
                {
                    foreach (string propertyName in dbEntry.OriginalValues.PropertyNames)
                    {
                        if (IsAttributeAuditable(tableName, propertyName))
                        {
                            // For updates, we only want to capture the columns that actually changed
                            if (!object.Equals(dbEntry.OriginalValues.GetValue<object>(propertyName), dbEntry.CurrentValues.GetValue<object>(propertyName)))
                            {
                                result.Add(CreateAuditLog(username,
                                    changeTime,
                                    AuditEventTypes.Modified,
                                    tableName,
                                    dbEntry.CurrentValues.GetValue<object>(keyName).ToString(),
                                    propertyName,
                                    dbEntry.OriginalValues.GetValue<object>(propertyName) == null ? null : dbEntry.OriginalValues.GetValue<object>(propertyName).ToString(),
                                    dbEntry.CurrentValues.GetValue<object>(propertyName) == null ? null : dbEntry.CurrentValues.GetValue<object>(propertyName).ToString()));
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }

            return result;
        }
예제 #5
0
        public static void Initialize()
        {
            try
            {
                if (_context == null)
                    _context = new ApplicationContext();
                if (string.IsNullOrEmpty(_filename))
                    _filename = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/coa.csv";

                DbInitializerHelper.InsertAdminUser();

                if (_context.Users.Count() == 0)
                    DbInitializerHelper.InitialUserAndSecurityModel();

                Company company = null;
                if (_context.Companies.Count() == 0)
                    company = DbInitializerHelper.CreateDefaultCompany();
                else
                    company = _context.Companies.FirstOrDefault();

                FiscalYear fy = null;
                if (_context.FiscalYears.Count() == 0)
                    fy = InitFiscalYear();

                List<PaymentTerm> paymentTerms = null;
                if (_context.PaymentTerms.Count() == 0)
                    paymentTerms = InitPaymentTerms();

                if (_context.AccountClasses.Count() == 0)
                    DbInitializerHelper.InitializeAccountClasses();

                if (_context.Accounts.Count() == 0)
                {
                    DbInitializerHelper.LoadChartOfAccountsFromFile(_filename, company.Id);
                    DbInitializerHelper.UpdateAccountsParentCodes(_filename);
                }

                GeneralLedgerSetting glSetting = null;
                if (_context.GeneralLedgerSettings.Count() == 0)
                    glSetting = InitGeneralLedgerSetting();

                if (_context.Taxes.Count() == 0)
                    DbInitializerHelper.InitTax();

                Vendor vendor = null;
                if (_context.Vendors.Count() == 0)
                    vendor = DbInitializerHelper.InitVendor();

                Customer customer = null;
                if (_context.Customers.Count() == 0)
                    customer = DbInitializerHelper.InitCustomer();

                List<Item> items = null;
                if (_context.Items.Count() == 0)
                    items = InitItems();

                List<Bank> banks = null;
                if (_context.Banks.Count() == 0)
                    banks = InitBanks();

                
            }
            catch
            {
            }
            finally
            {
                _context.Dispose();
            }
        }