Esempio n. 1
0
        public void ChangeCategoryName(int categoryId = 0)
        {
            var item = new NewsSystem.Models.Category();

            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                // Save changes here
            }
        }
        public void ListViewCategory_InsertItem()
        {
            var item = new Category();
            TryUpdateModel(item);

            if (ModelState.IsValid)
            {
                NewsSystemDbContext db = new NewsSystemDbContext();
                db.Categories.Add(item);
                db.SaveChanges();
            }
        }
        public Category Create(string name)
        {
            var newCategory = new Category()
            {
                Name = name
            };

            this.categories.Add(newCategory);

            this.categories.SaveChanges();

            return newCategory;
        }
Esempio n. 4
0
 public void ListViewCategories_InsertItem()
 {
     var name = (this.ListViewCategories.InsertItem.FindControl("tbName") as TextBox).Text;
     var item = new Category()
     {
         Name = name
     };
     TryUpdateModel(item);
     if (ModelState.IsValid)
     {
         this.dbContext.Categories.Add(item);
         this.dbContext.SaveChanges();
         ErrorSuccessNotifier.AddSuccessMessage("Category inserted!");
     }
 }
        public void FormViewIsertCategory_InsertItem()
        {
            var item = new NewsSystem.Models.Category();

            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                ErrorSuccessNotifier.AddSuccessMessage("Category added.");
                this.dbContext.Categories.Add(item);
                this.dbContext.SaveChanges();
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("Cannot create category!");
            }
        }
 public void ListViewCategories_InsertItem()
 {
     var item = new Category();
     TryUpdateModel(item);
     if (ModelState.IsValid)
     {
         try
         {
             this.context.Categories.Add(item);
             this.context.SaveChanges();
         }
         catch (DbUpdateException)
         {
             this.LabelValidation.Text = string.Format("Category {0} already exists", item.Name);
         }
     }
 }
        public void CategoriesListView_InsertItem()
        {
            var item = new Category();
            TryUpdateModel(item);

            if(string.IsNullOrWhiteSpace(item.Name))
            {
                ErrorSuccessNotifier.AddErrorMessage("Category Name could not be empty");
            }
            else if (db.Categories.Any(c => c.Name == item.Name))
            {
                ErrorSuccessNotifier.AddErrorMessage("Category Name already exists.");
            }
            else
            {
                if (ModelState.IsValid)
                {
                    db.Categories.Add(item);
                    db.SaveChanges();
                    ErrorSuccessNotifier.AddSuccessMessage("Category successfully created.");
                }
            }
        }