コード例 #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 void DeleteCategory(Category category)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(category).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #3
0
 public static void UpdateSidbar(Sidebar sidebar)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(sidebar).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
コード例 #4
0
 public static void DeletePage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(page).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #5
0
 public static bool UpdatePage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Entry(page).State = EntityState.Modified;
         return(db.SaveChanges() > 0);
     }
 }
コード例 #6
0
 public static bool AddPage(Page page)
 {
     using (var db = new ElectroSterkDbContext())
     {
         db.Pages.Add(page);
         return(db.SaveChanges() > 0);
     }
 }
コード例 #7
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");
        }
コード例 #8
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);
        }