예제 #1
0
        public IActionResult Create(CategoryModel category)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Category newCategory = new Category()
                    {
                        Name      = category.Name,
                        AddedDate = category.AddedDate
                    };

                    _category.AddCategory(newCategory);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            return(View(category));
        }
예제 #2
0
        public ActionResult Create(Category category)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_category.CheckCategoryNameExists(category.CategoryName))
                    {
                        ModelState.AddModelError("", CommonMessages.CategoryAlreadyExistsMessages);
                        return(View(category));
                    }
                    else
                    {
                        category.CreateDate = DateTime.Now;
                        category.UserId     = Convert.ToInt64(_sessionHandler.UserId);
                        _category.AddCategory(category);
                        TempData["CategorySuccessMessages"] = CommonMessages.CategorySuccessMessages;
                        return(RedirectToAction("Create", "Category"));
                    }
                }

                return(View(category));
            }
            catch
            {
                return(View());
            }
        }
예제 #3
0
        public IActionResult AddCategory(Category category)
        {
            try
            {
                _logger.LogInformation("وارد شدن به متدAddCategory");
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Values.SelectMany(a => a.Errors).Select(a => a.ErrorMessage);
                    _logger.LogError("mode not valid");
                    return(BadRequest(string.Join(",", errors)));
                }
                var result = _category.AddCategory(new Category
                {
                    CategoryName = category.CategoryName,
                });

                if (result.IsSucceed)
                {
                    _logger.LogInformation("دسته بندی با موفقیت اضافه شد");
                    return(Ok(result.Data));
                }
                return(BadRequest(string.Join(",", result.Errors)));
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #4
0
        public void RemoveCategory_RemoveSubCategoryWithDeeperTree_Success()
        {
            //Arrange
            const int subCategoriesLevels = 2;
            const int numberOfUsers       = 5;

            var rootCategory        = new Category("Root Category");
            var categoryToBeRemoved = new Category("To Be Removed");

            categoryToBeRemoved.AddCategory(new Category("Category X"));

            for (var i = 0; i < numberOfUsers; i++)
            {
                var currentUser = new User($"User{i}");
                categoryToBeRemoved.AddUser(currentUser);
            }

            ICategory nextLevel = categoryToBeRemoved;

            for (var i = 0; i < subCategoriesLevels; i++)
            {
                var currentCategory = new Category($"Category{i}");
                nextLevel.AddCategory(currentCategory);
                nextLevel = nextLevel.Categories.First();
                nextLevel.AddCategory(new Category($"DeeperCategory{i}"));
            }

            rootCategory.AddCategory(categoryToBeRemoved);

            var listWithAllSubCategories = (IList <ICategory>) typeof(Category)
                                           .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                           .First(x => x.FieldType == typeof(IList <ICategory>))
                                           .GetValue(rootCategory);

            categoryToBeRemoved = (Category)listWithAllSubCategories
                                  .First(x => x.Name == categoryToBeRemoved.Name);

            //Act
            rootCategory.RemoveCategory(categoryToBeRemoved);

            Assert.That(rootCategory.Categories.Count() == subCategoriesLevels);
            Assert.That(rootCategory.Categories.First().Categories.Count() == subCategoriesLevels);
            Assert.That(rootCategory.Categories.First().Categories.First().Categories.Count() == 1);
        }
 public IActionResult Create([Bind("Id,Name,Description")] Category category)
 {
     if (ModelState.IsValid)
     {
         _repo.AddCategory(category);
         _repo.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(category));
 }
예제 #6
0
        public IActionResult Category(string categoryName)
        {
            //Category add
            categoryContext.AddCategory(categoryName);
            //category info to view
            CategoryViewModel categoryViewModel = new CategoryViewModel {
                categories = categoryContext.getCategories()
            };

            return(View(categoryViewModel));
        }
예제 #7
0
 public IActionResult CreateCategory(CategoryDto category, bool res)
 {
     _logger.LogWarning("متد CreateCategory اجرا شد ");
     _category.AddCategory(category, res);
     if (res == false)
     {
         _logger.LogError("نام دسته بندی تکراری است");
         return(BadRequest("Category is Duplicate"));
     }
     _logger.LogInformation("دسته بندی ایجاد شد");
     return(RedirectToAction("Index"));
 }
예제 #8
0
파일: Category.cs 프로젝트: Abnertd/public
    public void AddCategory()
    {
        int    Cate_ParentID        = tools.CheckInt(Request.Form["Cate_ParentID"]);
        string Cate_Name            = tools.CheckStr(Request.Form["Cate_Name"]);
        int    Cate_TypeID          = tools.CheckInt(Request.Form["Cate_TypeID"]);
        string Cate_Img             = tools.CheckStr(Request.Form["Cate_Img"]);
        int    Cate_ProductTypeID   = 0;
        int    Cate_Sort            = tools.CheckInt(Request.Form["Cate_Sort"]);
        int    Cate_IsFrequently    = tools.CheckInt(Request.Form["Cate_IsFrequently"]);
        int    Cate_IsActive        = tools.CheckInt(Request.Form["Cate_IsActive"]);
        int    Cate_Count_Brand     = 0;
        int    Cate_Count_Product   = 0;
        string Cate_SEO_Path        = tools.CheckStr(Request.Form["Cate_SEO_Path"]);
        string Cate_SEO_Title       = tools.CheckStr(Request.Form["Cate_SEO_Title"]);
        string Cate_SEO_Keyword     = tools.CheckStr(Request.Form["Cate_SEO_Keyword"]);
        string Cate_SEO_Description = tools.CheckStr(Request.Form["Cate_SEO_Description"]);
        string Cate_Site            = Public.GetCurrentSite();

        if (Cate_Name.Length == 0)
        {
            Public.Msg("error", "错误信息", "请填写类别名称!", false, "{back}");
        }

        CategoryInfo entity = new CategoryInfo();

        entity.Cate_ParentID        = Cate_ParentID;
        entity.Cate_Name            = Cate_Name;
        entity.Cate_TypeID          = Cate_TypeID;
        entity.Cate_Img             = Cate_Img;
        entity.Cate_ProductTypeID   = Cate_ProductTypeID;
        entity.Cate_Sort            = Cate_Sort;
        entity.Cate_IsFrequently    = Cate_IsFrequently;
        entity.Cate_IsActive        = Cate_IsActive;
        entity.Cate_Count_Product   = Cate_Count_Product;
        entity.Cate_Count_Brand     = Cate_Count_Brand;
        entity.Cate_SEO_Path        = Cate_SEO_Path;
        entity.Cate_SEO_Title       = Cate_SEO_Title;
        entity.Cate_SEO_Keyword     = Cate_SEO_Keyword;
        entity.Cate_SEO_Description = Cate_SEO_Description;
        entity.Cate_Site            = Cate_Site;

        if (MyBLL.AddCategory(entity, Public.GetUserPrivilege()))
        {
            Public.Msg("positive", "操作成功", "操作成功", true, "category_add.aspx?parent_id=" + entity.Cate_ParentID);
        }
        else
        {
            Public.Msg("error", "错误信息", "操作失败,请稍后重试", false, "{back}");
        }
    }
        public IActionResult AddCategory(CategoryInputViewModel model)
        {
            if (ModelState.IsValid)
            {
                Category c = new Category
                {
                    Name = model.Name
                };

                _reposCategory.AddCategory(c);

                return(RedirectToAction("CategoryList"));
            }
            return(View());
        }
예제 #10
0
        public ActionResult AddCategories(AddCategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var e = icategory.AddCategory(model, UserId);
                if (e == "Saved")
                {
                    ViewBag.ModelMessage = model.CategoryName + " Added";
                    return(View());;
                }
                ViewBag.ModelMessage = "Category already Exist";

                return(View(model));
            }
            ViewBag.ModelMessage = "Failed to create Category model Error \n";

            return(View(model));
        }
예제 #11
0
        private CategoryEntity AddCategoryInternal(string categoryName)
        {
            var finalCategoryName = categoryName;

            if (finalCategoryName != null)
            {
                finalCategoryName = finalCategoryName.Trim();
            }
            var allCategories = _categoryRepository.GetCategories();

            if (!string.IsNullOrEmpty(finalCategoryName) && allCategories.SingleOrDefault(c => c.CategoryName.ToLower() == finalCategoryName.ToLower()) == null)
            {
                var categories   = allCategories.Select(c => c.CategorySlug).ToList();
                var categorySlug = finalCategoryName.GetUniqueSlug(categories);
                var entity       = new CategoryEntity {
                    CategoryName = finalCategoryName, CategorySlug = categorySlug
                };
                entity.CategoryID = _categoryRepository.AddCategory(entity);
                return(entity);
            }
            return(null);
        }
예제 #12
0
 public IActionResult GetCategorys(Category category)
 {
     _category.AddCategory(category);
     return(Created(HttpContext.Request.Scheme + "://" + HttpContext.Request.Host + HttpContext.Request.Path + "/" +
                    category.Id, category));
 }
예제 #13
0
 public bool AddCategory(Category Newcategory)
 {
     _category.AddCategory(Newcategory);
     return(true);
 }
예제 #14
0
 public int AddCategory(ICategory _category, string category, int TenantID, int UserID, int BrandID)
 {
     _categoryList = _category;
     return(_categoryList.AddCategory(category, TenantID, UserID, BrandID));
 }
        public bool Post(Category category)
        {
            bool result = _category.AddCategory(category);

            return(result);
        }
예제 #16
0
 public IActionResult AddCategory(CategoryModel catModel)
 {
     icategory.AddCategory(catModel);
     return(Ok(HttpStatusCode.OK));
 }