Esempio n. 1
0
        public ActionResult AddBlog(AddBlogViewModel addBlogViewModel)
        {
            Response response = new Response()
            {
                Code = 0
            };
            Blog blog;

            if (ModelState.IsValid)
            {
                var category = categoryManager.Find(addBlogViewModel.CategoryId);
                if (category == null || category.Type != CategoryType.General)
                {
                    response.Message = "栏目不匹配或者未找到!";
                    return(Json(response));
                }
                if (blogManager.Find(b => b.Title == addBlogViewModel.Title) != null)
                {
                    response.Message = "标题重复了!";
                    return(Json(response));
                }
                blog          = Mapper.Map <Blog>(addBlogViewModel);
                blog.Category = category;
                response      = blogManager.AddBlog(blog);
            }
            else
            {
                response.Message = "输入不合法!";
            }
            return(Json(response));
        }
Esempio n. 2
0
        // GET: Category/Edit/5
        public ActionResult Edit(int id)
        {
            CategoryViewModel model    = null;
            Category          category = categoryManager.Find(id);

            if (category != null)
            {
                model = Mapper.Map <CategoryViewModel>(category);
                model = PrepareViewModel(model);
            }

            return(View(model));
        }
Esempio n. 3
0
        /// <summary>
        /// 添加栏目
        /// </summary>
        /// <param name="id">父栏目ID</param>
        /// <returns></returns>
        public ActionResult Add(int?id)
        {
            Category _category = new Category()
            {
                ParentID = 0
            };

            if (id != null && id > 0)
            {
                var _parent = categoryManager.Find((int)id);
                if (_parent != null && _parent.Type == CategoryType.General)
                {
                    _category.ParentID = (int)id;
                }
            }
            return(View(_category));
        }