public IActionResult Create() { //var blog = new Blog(); var blog = new BlogCreateModel(); return(View(blog)); }
public static Blog ConvertFromBlogCreateModel(BlogCreateModel blogCreate) { return(new Blog { Title = blogCreate.Title, ImageUrl = blogCreate.ImageUrl, Description = blogCreate.Description, }); }
public async Task <IActionResult> CreateBlog([FromBody] BlogCreateModel model) { var blog = _mapper.Map <BlogDTO>(model); var result = await _blogService.CreateBlog(blog, Request.GetToken()); return(CreatedAtAction(nameof(GetBlogById), new { id = result.Id }, result)); }
public async Task <bool> InsertAsync(BlogCreateModel blogModel) { var entity = this.Mapper.Map <T_Blog>(blogModel); if (blogModel.IsPublish) { entity.PublishDate = DateTime.Now; } var imgList = WebHelper.GetHtmlImageUrlList(entity.ContentHtml).ToList(); if (imgList.Count > 0) { entity.ImgUrl = imgList[0]; } List <T_BlogTag> tagEntityList = new List <T_BlogTag>(); if (blogModel.PersonTags != null && blogModel.PersonTags.Count > 0) { List <long> blogTagList = new List <long>(); blogModel.PersonTags.ForEach(p => { if (!string.IsNullOrEmpty(p.Name)) { var tagTask = this.TagRepository.FindAsync(r => r.Name == p.Name.Trim() && r.UserId == UserContext.UserId); var tag = tagTask.Result; if (tag == null) { tag = new T_BlogTag { Id = Helper.GetLongSnowId(), Name = p.Name, UserId = UserContext.UserId, UserName = UserContext.UserName }; tagEntityList.Add(tag); } blogTagList.Add(tag.Id); } }); entity.BlogTags = string.Join(",", blogTagList); } var result = await this.DbSession.ExcuteAsync(async delegate { this.BeforeInsert(entity); await this.Repository.InsertAsync(entity); if (tagEntityList.Count > 0) { await this.TagRepository.BatchInsertAsync(tagEntityList); } await this.DbSession.SaveChangesAsync(); }); return(result); }
public static Blog ConvertFromCreateModel(BlogCreateModel blogCreate) { return(new Blog { ImageURL = blogCreate.ImageURL, Section = blogCreate.Section, Title = blogCreate.Title, BlogNote = blogCreate.BlogNote, FullDescription = blogCreate.FullDescription }); }
public IActionResult Create(BlogCreateModel model) { if (ModelState.IsValid) { Blog blog = ModelConverter.ConvertFromBlogCreateModel(model); BlogService.Add(blog); return(RedirectToAction("Overview")); } else { return(View(model)); } }
public IActionResult Create(BlogCreateModel blogCreate) { if (ModelState.IsValid) { var blog = ModelConverter.ConvertFromCreateModel(blogCreate); var converted = SectionConverter.ConvertToSection(blog); BlogService.CreateBlog(converted); return(RedirectToAction("Index")); } else { return(View(blogCreate)); } }
public async Task <IActionResult> UpdateBlogAsync([BindRequired, FromRoute] Guid id, [FromForm] BlogCreateModel blogUpdateModel) { Require.Objects.NotNull(blogUpdateModel, nameof(blogUpdateModel)); await UpdateDataAsync(_blogService, _imageService, id, blogUpdateModel, blogUpdateModel.Images, _mapper); return(Ok()); }
public async Task <ActionResult <BlogInfoModel> > CreateBlogAsync([FromForm] BlogCreateModel blogCreateModel) { Require.Objects.NotNull(blogCreateModel, nameof(blogCreateModel)); return(await CreatedItemAsync <BlogDto, BlogCreateModel, BlogInfoModel, Guid>(_blogService, _imageService, blogCreateModel, blogCreateModel.Images, _mapper)); }
public async Task <bool> Save([FromBody] BlogCreateModel editInfo) { return(await blogService.InsertAsync(editInfo)); //if (ModelState.IsValid) //{ // //TransactionManager.Excute(delegate // //{ // // Blog blogInfo = MapperManager.Map<Blog>(editInfo); // // if (!string.IsNullOrEmpty(editInfo.HexId)) // // { // // isEdit = true; // // blogInfo.Id = Convert.ToInt64(Helper.FromHex(editInfo.HexId)); // // } // // DbContextManager dbContext = new DbContextManager(); // // string[] imgList = WebHelper.GetHtmlImageUrlList(blogInfo.ContentHtml); // // if (imgList.Length > 0) // // { // // blogInfo.ImgUrl = string.Join(",", imgList); // // } // // if (!blogInfo.IsMarkDown) // // { // // blogInfo.Content = HttpUtility.HtmlEncode(blogInfo.ContentHtml); // // } // // if (blogInfo.IsPublish) // // { // // blogInfo.PublishDate = DateTime.Now; // // } // // List<string> tagList = new List<string>(); // // if (!string.IsNullOrEmpty(editInfo.PersonTags)) // // { // // int fakeId = 0; // // Dictionary<string, string> dicts = JsonConvert.DeserializeObject<Dictionary<string, string>>(editInfo.PersonTags); // // foreach (KeyValuePair<string, string> item in dicts) // // { // // if (!string.IsNullOrEmpty(item.Value)) // // { // // if (item.Key.Contains("newData")) // // { // // string value = item.Value.Trim(); // // BlogTag tag = _tagService.GetEntity(b => b.Name == value); // // if (tag == null) // // { // // tag = new BlogTag() // // { // // Id = fakeId++, // // Name = value, // // }; // // if (UserContext.LoginUser != null) // // { // // tag.UserId = UserContext.LoginUser.Id; // // } // // FillAddModel(tag); // // tag = _tagService.Insert(tag); // // // tag = dbContext.Add(tag); // // } // // tagList.Add(tag.Id.ToString()); // // } // // else if (!string.IsNullOrEmpty(item.Key)) // // { // // tagList.Add(item.Key); // // } // // } // // } // // } // // blogInfo.BlogTags = string.Join(",", tagList); // // if (isEdit) // // { // // _blogService.UpdateEntityFields(blogInfo, // // "Title", "ContentHtml", "Content", "TypeId", "CatId", "PersonTop", "Private", // // "Publish", "CanCmt", "MarkDown", "BlogTags", "PublishDate"); // // } // // else // // { // // blogInfo = FillAddModel(blogInfo); // // blogInfo = _blogService.Insert(blogInfo); // // } // // result.Resultdata = "/article/" + blogInfo.UserName + "/" + blogInfo.HexId; // //}); //} //else //{ // result.Success = false; // foreach (var key in ModelState.Keys) // { // var modelstate = ModelState[key]; // if (modelstate.Errors.Any()) // { // result.Message = modelstate.Errors.FirstOrDefault().ErrorMessage; // break; // } // } //} //return Json(result, JsonRequestBehavior.AllowGet); }
public IActionResult Create() { BlogCreateModel model = new BlogCreateModel(); return(View(model)); }
public async Task <IActionResult> UpdateBlog(int id, [FromBody] BlogCreateModel model) { await _blogService.UpdateBlog(id, _mapper.Map <BlogDTO>(model), Request.GetToken()); return(NoContent()); }