Esempio n. 1
0
        private List <dynamic> GetPeropers(string id)
        {
            List <dynamic> fieldInfos = new List <dynamic>();

            switch (id)
            {
            case "1":
                RaysBlog.Model.BlogCategory category = new Model.BlogCategory();
                fieldInfos.Add(new { field = nameof(category.Id).Substring(0, 1).ToLower() + nameof(category.Id).Substring(1), title = "ID", width = 50, sort = true, hide = true, @fixed = "left", unresize = true });
                fieldInfos.Add(new { field = nameof(category.No).Substring(0, 1).ToLower() + nameof(category.No).Substring(1), title = "序号", width = 80, sort = true, unresize = true });
                fieldInfos.Add(new { field = nameof(category.CategoryName).Substring(0, 1).ToLower() + nameof(category.CategoryName).Substring(1), title = "分类名称", width = 200 });
                fieldInfos.Add(new { field = nameof(category.CreateDate).Substring(0, 1).ToLower() + nameof(category.CreateDate).Substring(1), title = "创建时间", width = 200, sort = true, unresize = true });
                fieldInfos.Add(new { field = nameof(category.IsEnabled).Substring(0, 1).ToLower() + nameof(category.IsEnabled).Substring(1), title = "是否启用", width = 80, unresize = true });
                fieldInfos.Add(new { field = nameof(category.Remark).Substring(0, 1).ToLower() + nameof(category.Remark).Substring(1), title = "备注", width = 200 });
                break;
            }
            fieldInfos.Add(new { field = "right", width = 178, align = "center", toolbar = "#toolBar" });
            return(fieldInfos);
        }
Esempio n. 2
0
        //[AutoValidateAntiforgeryToken]
        public IActionResult Update()
        {
            dynamic obj = null;

            (bool, string)IsSuccess = (false, "");
            string typeId = Request.Form["typeId"].ToString(), action = Request.Form["action"].ToString();

            if (string.IsNullOrEmpty(typeId) || string.IsNullOrEmpty(action))
            {
                obj = new { code = 0, tid = -1, msg = "请求异常" };
                return(Json(obj));
            }
            switch (typeId)
            {
                #region 分类添加和修改
            case "1":
                var caidStr = Request.Form["CategoryId"].ToString();
                var caName  = Request.Form["CategoryName"].ToString();
                if (!string.IsNullOrEmpty(caName))
                {
                    if (!string.IsNullOrEmpty(action))
                    {
                        if (action == "1")
                        {
                            if (!int.TryParse(caidStr, out var id))
                            {
                                obj = new { code = 0, tid = typeId, msg = "分类Id转换错误" };
                                return(Json(obj));
                            }
                            var m = new Model.BlogCategory
                            {
                                CategoryId   = id,
                                CategoryName = caName
                            };
                            IsSuccess = _categoryService.Update(m);
                        }
                        if (action == "0")
                        {
                            var m = new Model.BlogCategory
                            {
                                CategoryName = caName
                            };
                            IsSuccess = _categoryService.Add(m);
                        }
                    }
                    if (IsSuccess.Item1)
                    {
                        obj = new { code = 0, tid = typeId, msg = IsSuccess.Item2 };
                    }
                    else
                    {
                        obj = new { code = 1, tid = typeId, msg = IsSuccess.Item2 };
                    }
                }
                else
                {
                    obj = new { code = 2, tid = typeId, msg = "请求失败" };
                }
                break;

                #endregion
                #region 文章添加和修改
            case "2":
                var artidStr      = Request.Form["ArticleId"].ToString();
                var artName       = Request.Form["ArticleName"].ToString();
                var ar_caidStr    = Request.Form["CategoryId"].ToString();
                var tagName       = Request.Form["TagName"].ToString();
                var tagidStr      = Request.Form["TagId"].ToString();
                var body          = Request.Form["body"].ToString();
                var remark        = Request.Form["remark"].ToString();
                var TitileImgPath = Request.Form["TitleImgPath"].ToString();
                if (!string.IsNullOrEmpty(artName) && !string.IsNullOrEmpty(body) && !string.IsNullOrEmpty(artName) && !string.IsNullOrEmpty(TitileImgPath))
                {
                    if (!string.IsNullOrEmpty(action))
                    {
                        if (!int.TryParse(ar_caidStr, out var caid))
                        {
                            obj = new { code = 0, tid = typeId, msg = "分类Id转换错误" };
                            return(Json(obj));
                        }
                        if (action == "1")
                        {
                            if (!int.TryParse(artidStr, out var artid))
                            {
                                obj = new { code = 0, tid = typeId, msg = "文章Id转换错误" };
                                return(Json(obj));
                            }
                            Model.BlogTag tg = null;
                            if (int.TryParse(tagidStr, out var tgid))
                            {
                                tg = new Model.BlogTag
                                {
                                    TagId   = tgid,
                                    ArId    = artid,
                                    TagName = tagName ?? tagName.Trim()
                                };
                            }
                            var m = new Model.BlogArticle
                            {
                                ArticleId    = artid,
                                ArticleName  = artName,
                                Body         = body,
                                Remark       = remark,
                                IsPublished  = true,
                                PostDate     = DateTime.Now,
                                Category     = _categoryService.Get(caid),
                                Tag          = tg,
                                TitleImgPath = TitileImgPath
                            };
                            IsSuccess = _articleService.Update(m);
                        }
                        if (action == "0")
                        {
                            var m = new Model.BlogArticle
                            {
                                ArticleName = artName,
                                Body        = body,
                                Remark      = remark,
                                IsPublished = true,
                                PostDate    = DateTime.Now,
                                Category    = _categoryService.Get(caid),
                                Tag         = new Model.BlogTag {
                                    TagName = tagName
                                },
                                TitleImgPath = TitileImgPath
                            };
                            IsSuccess = _articleService.Add(m);
                        }
                    }
                    if (IsSuccess.Item1)
                    {
                        obj = new { code = 0, tid = typeId, msg = IsSuccess.Item2 };
                    }
                    else
                    {
                        obj = new { code = 1, tid = typeId, msg = IsSuccess.Item2 };
                    }
                }
                else
                {
                    obj = new { code = 2, tid = typeId, msg = "请求失败" };
                }
                break;

            default:
                obj = new { code = 2, tid = -1, msg = "请求异常" };
                break;
                #endregion
            }
            return(Json(obj));
        }