Esempio n. 1
0
        public static void Seed()
        {
            CodingSoldierDbContext context = null;

            try
            {
                context = new CodingSoldierDbContext();
                if (!context.Roles.Any())
                {
                    foreach (var role in GetIdentityRoles())
                    {
                        context.Roles.Add(role);
                    }
                }
                if (!context.Categories.Any())
                {
                    foreach (var category in GetCategories())
                    {
                        context.Categories.Add(category);
                    }
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }
        }
Esempio n. 2
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             _dbContext.Dispose();
         }
     }
     this.disposed = true;
 }