public ActionResult Create(CreateCategoryModel model)
        {
            try

            {
                if(ModelState.IsValid){

                    Category cat = new Category()
                    {
                        CategoryName = model.Name,
                        ParentCategoryID = model.ParentCategoryID,
                        AccessTypes = model.AccessTypes,
                        CreatedDate =DateTime.Now,
                        UpdatedDate = DateTime.Now,
                    };
                    CategoryService service = new CategoryService();
                    service.AddCategory(cat);
                    return RedirectToAction("Index");

                };
                // TODO: Add insert logic here

            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                ModelState.AddModelError("Error", "Có lỗi hệ thống xãy ra. không thể thêm dữ liệu.");

            }
            return View(model);
        }
Beispiel #2
0
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="categoryID">Initial value of the CategoryID property.</param>
 public static Category CreateCategory(global::System.Int32 categoryID)
 {
     Category category = new Category();
     category.CategoryID = categoryID;
     return category;
 }
 public static string CategoryLink(this UrlHelper helper, Category category)
 {
     return helper.RouteUrl("Category-View-Route", new { category = category.StaticName, area="Content"});
 }
Beispiel #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategories(Category category)
 {
     base.AddObject("Categories", category);
 }