public TEntity GetById(int Id)
 {
     using (var context = new ClickerContext())
     {
         return(context.Set <TEntity>().Find(Id));
     }
 }
 public List <TEntity> GetAll()
 {
     using (var context = new ClickerContext())
     {
         return(context.Set <TEntity>().ToList());
     }
 }
 public void Update(TEntity entity)
 {
     using (var context = new ClickerContext())
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Delete(TEntity entity)
 {
     using (var context = new ClickerContext())
     {
         context.Set <TEntity>().Remove(entity);
         context.SaveChanges();
     }
 }
 public void Create(TEntity entity)
 {
     using (var context = new ClickerContext())
     {
         context.Set <TEntity>().Add(entity);
         context.SaveChanges();
     }
 }
Exemple #6
0
        public static void Seed()
        {
            var context = new ClickerContext();

            if (context.Database.GetPendingMigrations().Count() == 0)
            {
                if (context.Categories.Count() == 0)
                {
                    context.Categories.AddRange(Categories);
                }

                if (context.Products.Count() == 0)
                {
                    context.Products.AddRange(Products);
                    context.AddRange(ProductCategories);
                }
            }

            context.SaveChanges();
        }