Exemplo n.º 1
0
 public ActionResult Index(string keyWord, long?classifyId, string classifyName, string orderField = "Article.ArticleDateTime", string orderDirection = "desc", int pageCurrent = 1, int pageSize = 30)
 {
     ViewBag.KeyWord      = keyWord;
     ViewBag.ClassifyId   = classifyId;
     ViewBag.ClassifyName = classifyName;
     return(PartialView("Index", ArticleRepository.GetPagedList(ArticleClassifyRepository.AdminQueryUnDelete(), (keyWord ?? "").Trim(), classifyId, orderField, orderDirection, pageCurrent, pageSize)));
 }
        public async Task <ActionResult> Delete(long id)
        {
            var result = new JsonModel {
                statusCode = 300, message = "删除失败,记录不存在!", closeCurrent = false
            };

            if (id < 1)
            {
                return(Json(result));
            }
            var model = await ArticleClassifyRepository.GetUnDeleteByIdAsync(id);

            if (model == null)
            {
                return(Json(result));
            }
            if (await ArticleClassifyRepository.IsLastChildAsync(model.Id))
            {
                result.message = "请先删除其子分类";
                return(Json(result));
            }
            if (await ArticleRepository.IsAnyRecordAsync(model.Id))
            {
                result.message = "请先删除文章记录";
                return(Json(result));
            }
            model.CommonStatus = CommonStatus.Deleted;
            await ArticleClassifyRepository.SaveAsync(model);

            await LogRepository.Insert(TableSource.ArticleClassifies, OperationType.Delete, "删除" + model.Name + "及其子分类", id);

            result.statusCode = 200;
            result.message    = "删除成功!";
            return(Json(result));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Edit(string navtabId, long id = 0)
        {
            var model = new ArticleModel {
                ArticleDateTime = DateTime.Now, Author = User.UserInfo.UserName, CommonStatus = CommonStatus.Enabled
            };

            if (id > 0)
            {
                var article = await ArticleRepository.GetByIdAsync(id);

                if (article == null)
                {
                    var json = new JsonModel {
                        message = "记录不存在了", statusCode = 300
                    };
                    return(Json(json, JsonRequestBehavior.AllowGet));
                }
                Mapper.Map(article, model);
                var classify = await ArticleClassifyRepository.GetUnDeleteByIdAsync(article.ClassifyId);

                if (classify != null)
                {
                    model.ClassifyName = classify.Name;
                }
            }
            return(PartialView(model));
        }
Exemplo n.º 4
0
        public ActionResult Search(string keyWord)
        {
            ViewBag.KeyWord = keyWord;
            var classify = SysConfigRepository.SeachClassifyId;

            if (string.IsNullOrEmpty(classify))
            {
                return(View());
            }
            var classifyArray = StringUtility.ConvertToBigIntArray(classify, ',').ToList();

            if (!classifyArray.Any())
            {
                return(View());
            }
            var classifySort = classifyArray.Select((d, sort) => new { d, sort }).ToList();
            var classifyList = ArticleClassifyRepository.QueryEnable()
                               .Where(d => classifyArray.Any(m => m == d.Id))
                               .ToList()
                               .Select(d => new { Classify = d, Id = classifySort.FirstOrDefault(m => m.d == d.Id) })
                               .OrderBy(d => d.Id.sort)
                               .Select(d => d.Classify)
                               .ToList();

            ViewBag.ClassifyList = classifyList;
            if (!classifyList.Any())
            {
                return(View());
            }
            ViewBag.ArticleList = ArticleRepository.GetListBySearch((keyWord ?? "").Trim(), classifyList.Select(d => d.Id).ToList(), 1, PageSize);

            return(View());
        }
Exemplo n.º 5
0
        public ActionResult Delete(long id)
        {
            var result = ArticleClassifyRepository.Delete(id);

            if (result.code == JsonModelCode.Succ)
            {
                LogRepository.Insert(TableSource.ArticleClassify, OperationType.Delete, result.data.ToString());
            }
            return(Json(result));
        }
        public async Task <ActionResult> Edit(ArticleClassifyModel model)
        {
            var result = new JsonModel();

            // 数据有误
            if (!ModelState.IsValid)
            {
                result.GetError(ModelState);
                return(Json(result));
            }

            ArticleClassify p = null;

            if (model.PId != 0)
            {
                p = await ArticleClassifyRepository.GetUnDeleteByIdAsync(model.PId);

                if (p == null)
                {
                    result.message = "找不到id为" + model.PId + "的主分类!";
                    return(Json(result));
                }
            }

            var             operationType   = OperationType.Insert;
            var             operationTitle  = "添加管文章分类";
            ArticleClassify articleClassify = null;

            if (model.Id > 0)
            {
                articleClassify = await ArticleClassifyRepository.GetByIdAsync(model.Id);

                if (articleClassify == null)
                {
                    result.message = "记录不存在了";
                    return(Json(result));
                }
                operationType  = OperationType.Update;
                operationTitle = "修改管文章分类";
            }
            else
            {
                articleClassify = new ArticleClassify();
            }
            Mapper.Map(model, articleClassify);
            articleClassify.CommonStatus = CommonStatus.Enabled;
            await ArticleClassifyRepository.SaveAsync(articleClassify, p);

            await LogRepository.Insert(TableSource.ArticleClassifies, operationType, operationTitle, articleClassify.Id);

            result.message = "保存成功!";
            result.Data    = articleClassify;
            return(Json(result));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> Index(long classifyId)
        {
            var classify = await ArticleClassifyRepository.GetEnableByIdAsync(classifyId);

            if (classify == null)
            {
                return(RedirectTo404(Url.Home(), "找不到记录!"));
            }
            ViewBag.Classify = classify;
            var viewCode = classify.PartialViewCode == ArticleListType.Image ? "ImageList" : "TextList";

            return(View(viewCode, ArticleRepository.GetPagedList("", classifyId, 1, PageSize)));
        }
Exemplo n.º 8
0
        public ActionResult GetClassify(long id)
        {
            var result     = new JsonModel();
            var articleClz = ArticleClassifyRepository.Get(id);

            if (articleClz == null)
            {
                result.msg = "找不到记录!";
                return(Json(result));
            }
            articleClz.PicUrl = AttachmentSvc.GetPicUrl(articleClz.PicAttaId, 100, 100);
            result.data       = articleClz;
            result.code       = JsonModelCode.Succ;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 9
0
        public async Task <ActionResult> Edit(ArticleModel model)
        {
            var json = new JsonModel();

            if (await ArticleClassifyRepository.IsLastChildAsync(model.ClassifyId))
            {
                ModelState.AddModelError("ClassifyName", "只能添加到最后一级子分类");
            }
            // 数据有误
            if (!ModelState.IsValid)
            {
                json.GetError(ModelState);
                return(Json(json));
            }
            var     operationType  = OperationType.Insert;
            var     operationTitle = "添加文章信息";
            Article article        = null;

            if (model.Id > 0)
            {
                article = await ArticleRepository.GetByIdAsync(model.Id);

                if (article == null)
                {
                    json.message = "记录不存在了";
                    return(Json(json));
                }
                operationType  = OperationType.Update;
                operationTitle = "修改文章信息";
            }
            else
            {
                article = new Article();
            }
            Mapper.Map(model, article);
            await ArticleRepository.SaveAsync(article);

            await LogRepository.Insert(TableSource.Articles, operationType, operationTitle, article.Id);

            await AttachmentSvc.BoundAttachment(article.Id, article.Pic, article.ArticleContent);

            return(Json(json));
        }
Exemplo n.º 10
0
        public ActionResult Save(ArticleClassifyModel model)
        {
            var             result = new JsonModel();
            ArticleClassify parent = null;

            if (model.PId != 0)
            {
                parent = ArticleClassifyRepository.Get(model.PId);
                if (parent == null)
                {
                    result.msg = "找不到id为" + model.PId + "的主分类!";
                    return(Json(result));
                }
            }

            var             operationType   = OperationType.Insert;
            ArticleClassify articleClassify = null;

            if (model.Id > 0)
            {
                articleClassify = ArticleClassifyRepository.Get(model.Id);
                if (articleClassify == null)
                {
                    result.msg = "记录不存在了";
                    return(Json(result));
                }
                operationType = OperationType.Update;
            }
            else
            {
                articleClassify = new ArticleClassify();
            }
            Mapper.Map(model, articleClassify);
            ArticleClassifyRepository.Save(articleClassify, parent);
            LogRepository.Insert(TableSource.ArticleClassify, operationType, articleClassify.Id);
            result.msg  = "保存成功!";
            result.code = JsonModelCode.Succ;
            result.data = articleClassify;
            return(Json(result));
        }
Exemplo n.º 11
0
        public ActionResult Edit(long id, string reUrl)
        {
            ViewBag.ReUrl = reUrl ?? Url.Action("Index");
            var model = new ArticleModel()
            {
                ArticleDateTime = DateTime.Now,
                ExecutiveEditor = User.UserModel.UserName,
                CommonStatus    = CommonStatus.Enabled,
                ArticleTarget   = ArticleTarget.ThisPage,
                PartialViewCode = ArticleDetailType.Article
            };

            if (id == 0)
            {
                return(View(model));
            }
            var article = ArticleRepository.Get(id);

            if (article == null)
            {
                ShowErrorMsg();
                return(Redirect(ViewBag.ReUrl));
            }
            Mapper.Map(article, model);
            var clz = ArticleClassifyRepository.Get(model.ClassifyId);

            if (clz != null)
            {
                model.ClassifyName = clz.Name;
            }
            if (!string.IsNullOrEmpty(model.FocusMap))
            {
                model.FocusMapList = JsonConvert.DeserializeObject <List <ArticleFocusMapModel> >(model.FocusMap);
            }
            return(View(model));
        }
Exemplo n.º 12
0
        public ActionResult GetZTreeJson()
        {
            var list = ArticleClassifyRepository.GetListByZTree();

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> GetZTreeJson()
        {
            var list = await ArticleClassifyRepository.GetListByZTreeAsync();

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Index()
        {
            var list = await ArticleClassifyRepository.GetListByZTreeAsync();

            return(PartialView("Index", JsonConvert.SerializeObject(list)));
        }
Exemplo n.º 15
0
        public Pager <ArticleListItemModel> GetPager(long clzId, PageSearchModel search)
        {
            var lstClzId = ArticleClassifyRepository.GetLstChildId(clzId);

            return(ArticleRepository.GetPager(lstClzId, search));
        }
Exemplo n.º 16
0
        public IEnumerable <ArticleSimpleModel> GetList(long clzId, int count)
        {
            var lstClzId = ArticleClassifyRepository.GetLstChildId(clzId);

            return(ArticleRepository.GetList(lstClzId, count));
        }