protected void saveButton_Click(object sender, EventArgs e)
        {
            _create = string.IsNullOrEmpty(articleIdField?.Value);
            if (_create)
            {
                int newid = ArticleManager.CreateArticle(
                    title.Text, content.Text);

                Response.Redirect("EditArticle.aspx?articleId=" +
                                  newid.ToString());
            }
            else
            {
                if (int.TryParse(articleIdField?.Value, out int articleId))
                {
                    ArticleManager.UpdateArticle(
                        new ArticleInfo(articleId, title.Text, content.Text));
                    Response.Redirect("EditArticle.aspx?articleId=" +
                                      articleIdField?.Value.ToString());
                }
                else
                {
                    throw new Exception("Unable to parse article id");
                }
            }
        }
        public async Task <ActionResult> AddArticle(string title, string content, string introContent, Guid[] categoryIds)
        {
            //未登录、内容不为空、标题不为空、分类id不属于自己
            if (title == null || content == null || title.Trim() == "" || content.Trim() == "")               //提交的信息为空
            {
                return(Json(new { status = "fail", result = "提交的信息不完整,请重试" }, JsonRequestBehavior.AllowGet)); //返回错误信息
            }
            //获取当前登陆的id,cookie的id需要解密
            string userCookieId = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message))
                {
                    return(Json(new { status = "fail", result = message }, JsonRequestBehavior.AllowGet));//返回错误信息
                }
            }
            string userId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (userId == null || userId.Trim() == "")                                                            //用户未登录
            {
                return(Json(new { status = "fail", result = "获取不到用户信息,请检查登陆状态" }, JsonRequestBehavior.AllowGet)); //返回错误信息
            }
            IArticleManager articleManager = new ArticleManager();

            //如果提交的分类不为空,循环自己所有的分类,对比是否正确
            if (categoryIds != null)
            {
                List <BlogCategoryDto> categoryDtoes = await articleManager.GetAllCategories(Guid.Parse(userId)); //获取分类对象集合

                List <Guid> currentUserCategoryIds = new List <Guid>();                                           //将分类对象中的分类id整合进一个集合中
                foreach (BlogCategoryDto category in categoryDtoes)
                {
                    currentUserCategoryIds.Add(category.Id);
                }
                for (int i = 0; i < categoryIds.Length; i++)              //循环检查提交的分类id是否和自身的分类id有对应
                {
                    if (!currentUserCategoryIds.Contains(categoryIds[i])) //如果提交的分类id与自身的分类id没有匹配项,提示错误
                    {
                        return(Json(new { status = "fail", result = "提交的分类与用户所拥有的分类不匹配,请重试!" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            Guid articleId = await articleManager.CreateArticle(title, content, introContent, categoryIds, Guid.Parse(userId));

            return(Json(new { status = "ok", result = "提交成功!", articleId }, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        private void EnsureAllArticlesExists(IEnumerable <TransferItemLine> lines, ArticleManager articleManager)
        {
            foreach (var line in lines)
            {
                if (string.IsNullOrWhiteSpace(line.ArticleNo) || articleManager.ArticleExists(line.ArticleNo))
                {
                    continue;
                }

                _attemptsToCreateArticle++;

                if (!articleManager.CreateArticle(line.ArticleNo, line.ArticleName, _priceCalcMethodsNo, _postingTemplate, _stockProfileNo))
                {
                    _failedAttemptsToCreateArticle++;
                    lstLog.Items.Add(string.Format("Kunne ikke opprette artikkel '{0} - {1}'", line.ArticleNo, line.ArticleName));
                }
            }
        }