예제 #1
0
        public IActionResult Create()
        {
            //var blog = new Blog();
            var blog = new BlogCreateModel();

            return(View(blog));
        }
예제 #2
0
 public static Blog ConvertFromBlogCreateModel(BlogCreateModel blogCreate)
 {
     return(new Blog
     {
         Title = blogCreate.Title,
         ImageUrl = blogCreate.ImageUrl,
         Description = blogCreate.Description,
     });
 }
예제 #3
0
        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));
        }
예제 #4
0
        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);
        }
예제 #5
0
 public static Blog ConvertFromCreateModel(BlogCreateModel blogCreate)
 {
     return(new Blog
     {
         ImageURL = blogCreate.ImageURL,
         Section = blogCreate.Section,
         Title = blogCreate.Title,
         BlogNote = blogCreate.BlogNote,
         FullDescription = blogCreate.FullDescription
     });
 }
예제 #6
0
 public IActionResult Create(BlogCreateModel model)
 {
     if (ModelState.IsValid)
     {
         Blog blog = ModelConverter.ConvertFromBlogCreateModel(model);
         BlogService.Add(blog);
         return(RedirectToAction("Overview"));
     }
     else
     {
         return(View(model));
     }
 }
예제 #7
0
 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));
     }
 }
예제 #8
0
        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());
        }
예제 #9
0
        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));
        }
예제 #10
0
        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);
        }
예제 #11
0
        public IActionResult Create()
        {
            BlogCreateModel model = new BlogCreateModel();

            return(View(model));
        }
예제 #12
0
        public async Task <IActionResult> UpdateBlog(int id, [FromBody] BlogCreateModel model)
        {
            await _blogService.UpdateBlog(id, _mapper.Map <BlogDTO>(model), Request.GetToken());

            return(NoContent());
        }