/// <summary> /// Adds a New Category /// Level: Logic /// </summary> /// <param name="Category">The category</param> /// <param name="ImageURL">The image url</param> /// <param name="CategoryFK">The Parent ID</param> /// <returns>Category Result Enum</returns> public CategoryResult AddCategory(string Category, string ImageURL, int CategoryFK) { try { CategoriesRepository myRepository = new CategoriesRepository(); if (CategoryFK > 0) { //is child if (!myRepository.ChildCategoryExists(Category, CategoryFK)) { Common.Category myCategory = new Category(); myCategory.Category1 = Category; myCategory.ImageURL = ImageURL; myCategory.CategoryFK = CategoryFK; myRepository.AddCategory(myCategory); return(CategoryResult.Successful); } else { return(CategoryResult.Exists); } } else if (CategoryFK == 0) { //is parent if (!myRepository.ParentCategoryExists(Category)) { Common.Category myCategory = new Category(); myCategory.Category1 = Category; myCategory.ImageURL = ImageURL; myCategory.CategoryFK = null; myRepository.AddCategory(myCategory); return(CategoryResult.Successful); } else { return(CategoryResult.Exists); } } else { return(CategoryResult.Exists); } } catch (Exception Exception) { throw Exception; } }
public ActionResult Create([Bind("Name")] Category category) { if (ModelState.IsValid) { _categoriesRepository.AddCategory(category); return(RedirectToAction(nameof(Index))); } ViewBag.SelectedNav = "Dashboard"; return(View(category)); }
public void AddCategory(Category category) { var repo = new CategoriesRepository(_connectionString); repo.AddCategory(category); }