Esempio n. 1
0
        public static void AddProduct(Product product)
        {
            using (var db = new ElectroSterkDbContext())
            {
                if (product != null)
                {
                    db.Products.Add(product);
                    db.SaveChanges();
                }
            }



            //    if (string.IsNullOrEmpty(product.Name))
            //    {
            //        using (var db = new ElectroSterkDbContext())
            //        {
            //            product.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");
            //            return product;
            //        }
            //    }


            //    using (var db = new ElectroSterkDbContext())
            //    {
            //        if (db.Products.Any(x=> x.Name == product.Name))
            //        {
            //            product.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");

            //            return product;
            //        }
            //    }
        }
 public static Category GetCategory(int id)
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Categories.FirstOrDefault(x => x.Id == id));
     }
 }
 public static List <Category> GetCategories()
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Categories.ToArray().OrderBy(x => x.Sorting).ToList());
     }
 }
Esempio n. 4
0
 public static Sidebar GetSidebar(int id)
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Sidebars.FirstOrDefault(x => x.Id == id));
     }
 }
Esempio n. 5
0
 public static Page GetPage(int id)
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Pages.FirstOrDefault(x => x.Id == id));
     }
 }
Esempio n. 6
0
 public static List <Page> GetPages()
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Pages.ToArray().OrderBy(x => x.Sorting).ToList());
     }
 }
 public static void DeleteCategory(Category category)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(category).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
Esempio n. 8
0
 public static void UpdateSidbar(Sidebar sidebar)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(sidebar).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 9
0
 public static void DeletePage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(page).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
Esempio n. 10
0
 public static bool UpdatePage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(page).State = EntityState.Modified;
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 11
0
 public static bool AddPage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Pages.Add(page);
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 12
0
        public static Product GetProduct()
        {
            var product = new Product();

            using (var db = new ElectroSterkDbContext())
            {
                product.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");
            }

            return(product);
        }
        public static string UpdateCategory(string name, int id)
        {
            using (var db = new ElectroSterkDbContext())
            {
                if (db.Categories.Any(x => x.Name == name))
                {
                    return("titleused");
                }

                var category = db.Categories.FirstOrDefault(x => x.Id == id);

                category.Name = name;
                db.SaveChanges();
            }

            return("done");
        }
        public static string AddCategory(string name)
        {
            string id;

            using (var db = new ElectroSterkDbContext())
            {
                if (db.Categories.Any(x => x.Name == name))
                {
                    return("titletaken");
                }
                var category = new Category
                {
                    Name    = name,
                    Sorting = 100
                };

                db.Categories.Add(category);
                db.SaveChanges();
                id = category.Id.ToString();
            }

            return(id);
        }