コード例 #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;
            //        }
            //    }
        }
コード例 #2
0
 public static Category GetCategory(int id)
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Categories.FirstOrDefault(x => x.Id == id));
     }
 }
コード例 #3
0
 public static List <Category> GetCategories()
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Categories.ToArray().OrderBy(x => x.Sorting).ToList());
     }
 }
コード例 #4
0
 public static Sidebar GetSidebar(int id)
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Sidebars.FirstOrDefault(x => x.Id == id));
     }
 }
コード例 #5
0
 public static Page GetPage(int id)
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Pages.FirstOrDefault(x => x.Id == id));
     }
 }
コード例 #6
0
 public static List <Page> GetPages()
 {
     using (var db = new ElectroSterkDbContext())
     {
         return(db.Pages.ToArray().OrderBy(x => x.Sorting).ToList());
     }
 }
コード例 #7
0
 public static void DeleteCategory(Category category)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(category).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #8
0
 public static void UpdateSidbar(Sidebar sidebar)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(sidebar).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
コード例 #9
0
 public static void DeletePage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(page).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #10
0
 public static bool UpdatePage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(page).State = EntityState.Modified;
         return(db.SaveChanges() > 0);
     }
 }
コード例 #11
0
 public static bool AddPage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Pages.Add(page);
         return(db.SaveChanges() > 0);
     }
 }
コード例 #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);
        }
コード例 #13
0
        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");
        }
コード例 #14
0
        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);
        }