Example #1
0
        //
        // GET: /Category/Create
        public ActionResult Create(Guid? parentID)
        {
            Category e = new Category();
            e.ParentID = parentID;

            return View(e);
        }
Example #2
0
 public ActionResult Create(Guid? parentID, FormCollection collection)
 {
     // TODO: Add insert logic here
     Category e = new Category();
     UpdateModel(e);
     repo.Add(e);
     //repo.Save();
     return RedirectToAction("Index", new { parentID = e.ParentID });
 }
Example #3
0
        // Add/Delete
        //public Category Add(string name, int level, Guid? parentID)
        //{
        //    Category Category = new Category();
        //    Category.Name = name.Trim();
        //    Category.Level = level;
        //    Category.ParentID = parentID;
        //    DB.Categories.AddObject(Category);
        //    return Category;
        //}
        public Category Add(Category e)
        {
            e.ID = Guid.NewGuid();
            DB.Categories.AddObject(e);
            e.Level = e.Parent == null ? 1 : e.Parent.Level + 1;
            //SetFullname(e);
            //e.FullNameNoDiacritics = e.FullName.RemoveDiacritics();
            UpdateFullname(e);

            Save();
            return e;
        }
Example #4
0
        //public void Add(string Category1Name, string Category2Name, string Category3Name)
        //{
        //    //Category1
        //    if (string.IsNullOrEmpty(Category1Name)
        //        || string.IsNullOrEmpty(Category1Name.Trim())) return;
        //    Category Category1 = Get(Category1Name, 1, null);
        //    if (Category1 == null)
        //        Category1 = Add(Category1Name, 1, null);
        //    //Category2
        //    if (string.IsNullOrEmpty(Category2Name)
        //        || string.IsNullOrEmpty(Category2Name.Trim())) return;
        //    Category Category2 = Get(Category2Name, 2, Category1ID);
        //    Guid? Category2ID = Category2 != null ? Category2.ID : Insert(Category2Name, 2, Category1ID);
        //    //Category3
        //    if (string.IsNullOrEmpty(Category3Name)
        //        || string.IsNullOrEmpty(Category3Name.Trim())) return;
        //    Category Category3 = Get(Category3Name, 3, Category2ID);
        //    Guid? Category3ID = Category3 != null ? Category3.ID : Insert(Category3Name, 3, Category2ID);
        //}
        // Persistence
        public static void SetFullname(Category e)
        {
            if (e.Level == 1)
            {
                e.FullName = e.Name;
            }

            if (e.Level == 2)
            {
                e.FullName = e.Name + ", " + e.Parent.Name;
            }

            if (e.Level == 3)
            {
                e.FullName = e.Name + ", " + e.Parent.Name + ", " + e.Parent.Parent.Name;
            }
        }
Example #5
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);
 }
Example #6
0
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static Category CreateCategory(global::System.Guid id)
 {
     Category category = new Category();
     category.ID = id;
     return category;
 }
Example #7
0
 public string GetFullname(Category Category1, Category Category2, Category Category3)
 {
     return Category3 != null ? Category3.FullName : Category2 != null ? Category2.FullName : Category1 != null ? Category1.FullName : "";
 }
Example #8
0
 public void Delete(Category e)
 {
     DB.Categories.DeleteObject(e);
 }
Example #9
0
 public void UpdateFullname(Category e)
 {
     SetFullname(e);
     e.FullNameNoDiacritics = e.FullName.RemoveDiacritics();
 }