public async Task <Article> CreateArticle(NewArticleModel newArticle, string token) { var user = ServiceProvider.GetRequiredService <UserService>().GetCurrentUser(token); if (user == null) { throw new ApplicationException("Not logged in."); } var newUid = Guid.NewGuid(); var article = new Article { ArticleUid = newUid, AuthorUserUid = user.UserUid, Body = newArticle.Body, Description = newArticle.Description, Title = newArticle.Title, ArticleTags = newArticle.TagList.Select(s => new ArticleTag { TagUid = Context.GetTag(s) }).ToList(), UpdatedAt = DateTime.UtcNow, Slug = HttpUtility.UrlEncode($"{user.Username}_{newArticle.Title}") }; Context.Articles.Add(article); var count = await Context.SaveChangesAsync(); article.Author = user; return(count > 0 ? article : null); }
public Dictionary <string, object> UploadNewArticle([FromBody] NewArticleModel newArticleModel) { Dictionary <string, object> resultMsg = new Dictionary <string, object>(); resultMsg["result"] = DefineManager.RESULT_MSG_FAIL; try { Article newArticle = new Article(); newArticle.articleContent = newArticleModel.articleContent; newArticle.highlightText = newArticleModel.highlightText; newArticle.title = newArticleModel.title; newArticle.imgUrl = newArticleModel.imgUrl; string clientToken = newArticleModel.clientToken; if (clientToken != null) { LogManager.PrintLogMessage("BlogApiController", "UploadNewArticle", "token is available?: " + clientToken, DefineManager.LOG_LEVEL_DEBUG); string userDisplayName = httpsManager.IsTokenVerified(clientToken); if (userDisplayName != null) { try { newArticle.writer = userDisplayName; LogManager.PrintLogMessage("BlogApiController", "UploadNewArticle", "article title: " + newArticle.title + " highlight: " + newArticle.highlightText + " image url: " + newArticle.imgUrl + " content len: " + newArticle.articleContent.Length, DefineManager.LOG_LEVEL_DEBUG); myBlogDBManager.InsertNewArticle(newArticle); resultMsg["result"] = DefineManager.RESULT_MSG_OK; } catch (Exception except) { LogManager.PrintLogMessage("BlogApiController", "UploadNewArticle", "exception accepted while upload new article: " + except, DefineManager.LOG_LEVEL_ERROR); } } else { LogManager.PrintLogMessage("BlogApiController", "UploadNewArticle", "cannot recognize user, so you cannot insert new article", DefineManager.LOG_LEVEL_WARN); } } else { LogManager.PrintLogMessage("BlogApiController", "UploadNewArticle", "token is null", DefineManager.LOG_LEVEL_WARN); } } catch (Exception error) { LogManager.PrintLogMessage("BlogApiController", "UploadNewArticle", "request error accured: " + error, DefineManager.LOG_LEVEL_ERROR); } return(resultMsg); }
/// <summary> /// 新增 /// </summary> /// <param name="model"></param> public void Add(NewArticleModel model) { try { var registerCommand = _mapper.Map <AddNewArticleCommand>(model); Bus.SendCommand(registerCommand); } catch (Exception e) { Bus.RaiseEvent(new DomainNotification("", "出现错误,请稍后重试")); } }
public ActionResult _NewArticleModalPartial() { var auth = DependencyResolver.Current.GetService <IAuthProvider>(); var userGuid = auth.UserGuid; var repo = DependencyResolver.Current.GetService <IRepository>(); var model = new NewArticleModel(); ViewBag.Categories = repo.GetArticleCategories(); ViewBag.Statuses = repo.GetStatuses(userGuid); ViewBag.Markers = repo.GetMarkers(); ViewBag.Cities = repo.GetCities(); return(PartialView("Partial/_NewArticleModalPartial", model)); }
/// <summary> /// 创建文章 /// </summary> /// <param name="model">新建文章模型</param> public void CreateArticle(NewArticleModel model) { IRepository <Article> rep = Factory.Factory <IRepository <Article> > .GetConcrete <Article>(); Article a = new Article(model.Title, model.BriefTitle, model.Body, model.UserID, model.UserName, model.CategoryID, model.CategoryName, model.SourceUrl, model.SourceSite, model.ImgName); try { rep.Add(a); rep.PersistAll(); } catch { } }
public ActionResult SubmitArticle(NewArticleModel article) { if (ModelState.IsValid) { StoryLink articleEntity = new StoryLink() { Title = article.title, Url = article.Site, DateAdded = DateTime.UtcNow }; Storage.AddArticle(articleEntity); return(RedirectToAction("Index")); } return(View(article)); }
public bool AddNewArticle(NewArticleModel model, HttpPostedFileBase articlePhoto, HttpPostedFileBase articleTitlePhoto) { if (articleTitlePhoto != null) { model.TitlePhoto = FileProvider.SaveArticleTitlePhoto(articleTitlePhoto); model.TitlePhotoPreview = FileProvider.SaveArticleTitlePhotoPreview(articleTitlePhoto); } if (articlePhoto != null) { model.Photo = FileProvider.SaveArticlePhoto(articlePhoto); } if (string.IsNullOrEmpty(model.Title) && !string.IsNullOrEmpty(model.TitleEn)) { model.Title = model.TitleEn; } if (string.IsNullOrEmpty(model.Description) && !string.IsNullOrEmpty(model.DescriptionEn)) { model.Description = model.DescriptionEn; } if (string.IsNullOrEmpty(model.Text) && !string.IsNullOrEmpty(model.TextEn)) { model.Text = model.TextEn; } if (string.IsNullOrEmpty(model.SourcePhoto) && !string.IsNullOrEmpty(model.SourcePhotoEn)) { model.SourcePhoto = model.SourcePhotoEn; } if (string.IsNullOrEmpty(model.SourceUrl) && !string.IsNullOrEmpty(model.SourceUrlEn)) { model.SourceUrl = model.SourceUrlEn; } var repo = DependencyResolver.Current.GetService <IRepository>(); var auth = DependencyResolver.Current.GetService <IAuthProvider>(); var userGuid = auth.UserGuid; repo.AddNewArticle(model, userGuid); return(true); }
public void EditArticle(NewArticleModel model, string userGuid) { var trans = _db.Database.BeginTransaction(); try { var adder = GetUserByGuid(userGuid); var article = _db.article.First(m => m.Id == model.Id); model.CopyTo(article); article.BaseCategoryId = model.BaseCategoryId; article.MarkerId = model.MarkerId; article.CityId = model.CityId; if (model.StatusId == GetStatusByTag(MarkerStatuses.Published).Id&&article.status != GetStatusByTag(MarkerStatuses.Published)) { article.EditorId = adder.Id; article.PublishedDate = DateTime.Now; } else { article.EditorId = null; article.PublishedDate = DateTime.Now; } article.StatusId = model.StatusId; _db.articlesubcategory.RemoveRange(_db.articlesubcategory.Where(s => s.ArticleId == article.Id)); if (model.SubCategories != null) { _db.articlesubcategory.AddRange( model.SubCategories.Select(sc => new articlesubcategory { ArticleId = article.Id, CategoryId = sc })); } _db.SaveChanges(); trans.Commit(); } catch (Exception) { trans.Rollback(); throw; } }
public ActionResult NewArticle(NewArticleModel newArticleModel) { if (newArticleModel.Tags.Length > 0) { ITagService tagService = new TagService(); List <string> tagList = tagService.ParseTags(newArticleModel.Tags); List <tblTags> dbLinkedTags = tagService.FindOrAddTags(tagList); tblArticles article = new tblArticles() { Content = newArticleModel.Content, Header = newArticleModel.Header, Date = DateTime.Now, UserID = 1 }; this._articleManager.AddNewArticle(article); tagService.AttachTagToArticle(dbLinkedTags, article); } return(Redirect(Url.Content("~/"))); }
public JsonResult WritePost([FromForm] NewArticleModel articleModel, [FromQuery] string flag = "1") { var a = _articleService.GetByFilter(x => x.Title.Equals(articleModel.Title)); if (a != null) { return(new JsonResult("文章标题已存在,请重新输入")); } NewArticleModel mo = articleModel; mo.CreateTime = DateTime.Now; switch (flag) { case "3": //发布,状态变审核中 mo.Status = ArticleStatus.Verify; break; case "1": //只保存,不进入审核 mo.Status = ArticleStatus.Savedraft; break; default: mo.Status = ArticleStatus.Verify; break; } if (articleModel.BlogType == ArticleSource.Original) { if (_user != null) { mo.Author = _user.Name; } } _articleService.Add(mo); var error = _notifications.GetNotifications().Select(n => n.Value);//通知结果 return(new JsonResult(error)); }
protected void ArticlesAddBtn_Click(object sender, EventArgs e) { NewArticleModel model = new NewArticleModel(); // model. CMSService mycms = new CMSService(); //string _Pic=string.Empty; //if (!string.IsNullOrEmpty(ImgName)) //{ // _Pic = ImgName; //} string body = Request.Form["editorcontent"]; //if (Utils.Utils.GetHtmlImageUrlList(body).Length > 0) //{ // string k = Utils.Utils.GetHtmlImageUrlList(body)[0].Replace("/FLYUpload/Images/",""); // model.ImgName =k; //} //else //{ // model.ImgName = string.Empty; //} string[] k = FBS.Utils.Utils.GetHtmlImageUrlList(body); int point = 0; string url = ""; if (k.Length > 0) { foreach (string y in k) { if (!y.Contains("/plugins/emoticons/"))//表情 { url = y; break; } point++; } if (point == k.Length) { model.ImgName = string.Empty; } else { if (url.Contains("FLYUpload/Images/")) { model.ImgName = FBS.Utils.Utils.GetHtmlImageUrlList(body)[point]; } else { //网络图片 try { //String fileExt = Path.GetExtension(url).ToLower(); //System.Drawing.Image tempimage = System.Drawing.Bitmap.FromFile(url); //string filename = "/FLYUpload/Images/" + Guid.NewGuid().ToString() + fileExt; //tempimage.Save(filename); //tempimage.Dispose(); model.ImgName = url; } catch (Exception ee) { model.ImgName = string.Empty; } } } } else { model.ImgName = string.Empty; } model.Title = ArticleTitle.Text.ToString().Trim(); model.Body = body; model.CategoryID = new Guid(ArticleCategory.SelectedItem.Value); model.CategoryName = ArticleCategory.SelectedItem.Text.ToString().Replace("┣", "").Replace("-", ""); model.SourceSite = ArticleWeb.Text.ToString().Trim(); model.SourceUrl = ArticleLink.Text.ToString().Trim(); model.BriefTitle = ArticleBriefTitle.Text.ToString().Trim(); //从cookie获取用户名及用户的ID HttpCookie hc = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket fat = FormsAuthentication.Decrypt(hc.Value); model.UserID = new Guid(fat.Name); model.UserName = fat.UserData; mycms.CreateArticle(model); //Response.Redirect("ArticlesList.aspx?Type='add'"); Response.Write("<script>alert('添加成功')</script>"); }
public void Update(NewArticleModel updatemodel) { throw new System.NotImplementedException(); }