Esempio n. 1
0
        public IActionResult Update([FromBody] ArticleModel model)
        {
            ArticleInfo article = _articleBusiness.GetArticle(model.ArticleId);
            String      userId  = _userManager.GetUserId(User);

            if (article == null)
            {
                article           = new ArticleInfo();
                article.CreatedAt = DateTime.Now;
                article.CreatedBy = userId;
            }

            article.ArticleId      = model.ArticleId;
            article.ArticleContent = model.ArticleContent;
            article.ArticleOrder   = model.ArticleOrder;
            article.CreatedAt      = DateTime.Now;
            article.ImageUrl       = model.ImageUrl;
            article.Title          = model.Title;
            article.UserId         = userId;
            article.UpdatedAt      = DateTime.Now;
            article.UpdatedBy      = userId;
            article.ModuleId       = model.ModuleId;

            _articleBusiness.SaveArticle(article);

            return(Ok(new { article.ArticleId }));
        }
        public override Task <ModuleViewComponentResult> OnViewComponentLoad()
        {
            AdminArticleModel model   = new AdminArticleModel(this);
            ArticleInfo       article = null;

            // Update
            if (Request.Method == "POST")
            {
                String userId = _userManager.GetUserId(HttpContext.User);
                article = _articleBusiness.GetArticle(ArticleId);

                if (article == null)
                {
                    article           = new ArticleInfo();
                    article.CreatedAt = DateTime.UtcNow;
                    article.CreatedBy = userId;
                }

                article.ArticleId      = model.ArticleId;
                article.ArticleContent = model.ArticleContent;
                article.ArticleOrder   = model.ArticleOrder;
                article.CreatedAt      = DateTime.Now;
                article.ImageUrl       = model.ImageUrl;
                article.Title          = model.Title;
                article.UserId         = userId;
                article.UpdatedAt      = DateTime.UtcNow;
                article.UpdatedBy      = userId;
                article.ModuleId       = Module.ModuleId;

                _articleBusiness.SaveArticle(article);
            }

            if (article == null)
            {
                article = _articleBusiness.GetArticle(ArticleId);
            }

            if (article == null)
            {
                return(Task.FromResult(ModuleView("ArticleEdit", model)));
            }

            model.ArticleId      = ArticleId;
            model.ArticleContent = article.ArticleContent;
            model.ArticleOrder   = article.ArticleOrder;
            model.ImageUrl       = article.ImageUrl;
            model.Title          = article.Title;

            return(Task.FromResult(ModuleView("ArticleEdit", model)));
        }