コード例 #1
0
        public int Add(Category newCategory)
        {
            this.categories.Add(newCategory);
            this.categories.SaveChanges();

            return newCategory.Id;
        }
コード例 #2
0
        public Category GenerateCategory()
        {
            var category = new Category()
            {
                Name = "test-category"
            };

            return category;
        }
コード例 #3
0
        public int Add(string name)
        {
            var newCategory = new Category
            {
                Name = name
            };

            this.categoriesRepository.Add(newCategory);
            this.categoriesRepository.SaveChanges();
            return newCategory.Id;
        }
コード例 #4
0
        public int Add(string title, Visibility visibility)
        {
            var newCategory = new Category
            {
                Title = title,
                Visibility = visibility
            };

            this.categories.Add(newCategory);
            this.categories.SaveChanges();

            return newCategory.Id;
        }
コード例 #5
0
        public static MemoryRepository<Category> GetCategoriesRepository()
        {
            var categoriesRepository = new MemoryRepository<Category>();
            for (int i = 0; i < 10; i++)
            {
                var category = new Category
                {
                    Id = i,
                    Name = "category" + i
                };

                categoriesRepository.Add(category);
            }

            return categoriesRepository;
        }
コード例 #6
0
        protected void LinkButtonCreate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.TextBoxCategoryTitle.Text))
            {
                Notifier.AddErrorMessage("Category title is required!");
                return;
            }

            var visibility = this.DropDownVisibilities.SelectedIndex;
            var newCategory = new Category()
            {
                Title = this.TextBoxCategoryTitle.Text,
                Visibility = (Visibility)visibility
            };

            var id = this.Categories.Add(newCategory);

            if (id != 0)
            {
                Notifier.AddSuccessMessage("Category was successfully created!");
                Response.Redirect("~/Admin/EditCategories.aspx");
            }
        }
コード例 #7
0
        private int GetCategoryId(string categoryName)
        {
            var category = this.ForumSystemData.Categories
                               .All()
                               .FirstOrDefault(c => c.Name == categoryName);

            if (category == null)
            {
                category = new Category()
                {
                    Name = categoryName
                };

                this.ForumSystemData.Categories.Add(category);
                this.ForumSystemData.SaveChanges();
            }

            return category.ID;
        }