예제 #1
0
        public ActionResult Add(string categoryName, int isService)
        {
            // 判断新添加的categoryName 是否为空
            if (string.IsNullOrEmpty(categoryName))
            {
                return(RedirectToAction("List", new { msg = "分类名不能为空" }));
            }

            Category category = new Category();

            category.Id          = Guid.NewGuid();
            category.CategoryNO  = "Category_" + TimeManager.GetCurrentTimestamp();
            category.CreatedTime = DateTime.Now.Date;
            category.IsDeleted   = false;
            category.Name        = categoryName;
            category.IsService   = isService == 1 ? true : false;

            // 判断是否存在新添加的categoryName
            if (_categoryBLL.IsExist(categoryName))
            {
                return(RedirectToAction("List", new { msg = "该分类已存在,请重新添加" }));
            }

            // 添加新Category
            if (_categoryBLL.Add(category))
            {
                // 添加成功
                return(RedirectToAction("List", new { msg = "添加成功" }));
            }
            else
            {
                return(RedirectToAction("List", new { msg = "添加失败" }));
            }
        }