예제 #1
0
        public ActionResult Create(int? parentId, int categoryType, FormCollection form)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var category = new Category { MainPage = false, CategoryType = categoryType };
                    Category parent = null;
                    TryUpdateModel(category, new[] { "Name", "Title", "SortOrder", "SeoDescription", "SeoKeywords" });
                    category.Text = HttpUtility.HtmlDecode(form["Text"]);
                    if (parentId.HasValue)
                    {
                        parent = context.Category.First(c => c.Id == parentId);
                        parent.Children.Add(category);
                    }
                    else
                    {
                        context.AddToCategory(category);
                    }
                    context.SaveChanges();

                    string controllerName = GetControllerNameByCategoryType(categoryType);


                    return parent != null
                        ? RedirectToAction("Index", controllerName, new { area = "", category = parent.Name, subcategory = category.Name })
                        : RedirectToAction("Index", controllerName, new { area = "", category = category.Name });
                }
            }
            catch
            {
                return View();
            }
        }
예제 #2
0
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 /// <param name="mainPage">Initial value of the MainPage property.</param>
 /// <param name="categoryType">Initial value of the CategoryType property.</param>
 public static Category CreateCategory(global::System.Int32 id, global::System.String name, global::System.String title, global::System.Int32 sortOrder, global::System.Boolean mainPage, global::System.Int32 categoryType)
 {
     Category category = new Category();
     category.Id = id;
     category.Name = name;
     category.Title = title;
     category.SortOrder = sortOrder;
     category.MainPage = mainPage;
     category.CategoryType = categoryType;
     return category;
 }
예제 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Category EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategory(Category category)
 {
     base.AddObject("Category", category);
 }