public virtual async Task <BlogPostDto> UpdateAsync(Guid id, UpdateBlogPostDto input) { var blogPost = await BlogPostRepository.GetAsync(id); blogPost.SetTitle(input.Title); blogPost.SetShortDescription(input.ShortDescription); blogPost.SetContent(input.Content); if (blogPost.Slug != input.Slug) { await BlogPostManager.SetSlugUrlAsync(blogPost, input.Slug); } await BlogPostRepository.UpdateAsync(blogPost); return(ObjectMapper.Map <BlogPost, BlogPostDto>(blogPost)); }
public IActionResult Create(BlogPost post) { var author = HttpContext.Session.GetString(SessionKeyName); if (!ModelState.IsValid) { return(View()); } post.Id = BlogPostRepository.GetLastId() + 1; post.Author = author; post.CreateDate = DateTime.Now; BlogPostRepository.AddBlogPost(post); return(View()); }
public virtual async Task <PagedResultDto <BlogPostListDto> > GetListAsync(BlogPostGetListInput input) { var blogs = (await BlogRepository.GetListAsync()).ToDictionary(x => x.Id); var blogPosts = await BlogPostRepository.GetListAsync(input.Filter, input.BlogId, input.MaxResultCount, input.SkipCount, input.Sorting); var count = await BlogPostRepository.GetCountAsync(input.Filter); var dtoList = blogPosts.Select(x => { var dto = ObjectMapper.Map <BlogPost, BlogPostListDto>(x); dto.BlogName = blogs[x.BlogId].Name; return(dto); }).ToList(); return(new PagedResultDto <BlogPostListDto>(count, dtoList)); }
public virtual async Task <BlogPostDto> CreateAsync(CreateBlogPostDto input) { var author = await UserLookupService.GetByIdAsync(CurrentUser.GetId()); var blog = await BlogRepository.GetAsync(input.BlogId); var blogPost = await BlogPostManager.CreateAsync( author, blog, input.Title, input.Slug, input.ShortDescription, CurrentTenant.Id); await BlogPostRepository.InsertAsync(blogPost); return(ObjectMapper.Map <BlogPost, BlogPostDto>(blogPost)); }
public async Task <ActionResult> CreateCommentAsync(string id, [Bind(Include = "Author,Review")] BlogReviewViewModel item) { if (ModelState.IsValid) { item.CreatedDate = DateTime.Now.ToString(); BlogItemViewModel blog = await BlogPostRepository <BlogItemViewModel> .GetItemAsync(id); if (blog.UserReviews == null) { blog.UserReviews = new List <BlogReviewViewModel>(); } blog.UserReviews.Add(item); await BlogPostRepository <BlogItemViewModel> .UpdateItemAsync(blog.Id, blog); return(RedirectToAction("Details", new { id = blog.Id })); } return(View(item)); }
public HttpResponseMessage FetchPost(HttpRequestMessage request, int blogPostId) { HttpResponseMessage response = null; try { IBlogPostRepository blogPostRepository = new BlogPostRepository("easyBlog"); BlogPost blogPost = blogPostRepository.GetComplete(blogPostId); response = request.CreateResponse <BlogPost>(HttpStatusCode.OK, blogPost); } catch (Exception ex) { response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } return(response); }
public async Task <ActionResult> DetailsAsync(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BlogItemViewModel item = await BlogPostRepository <BlogItemViewModel> .GetItemAsync(id); if (item == null) { return(HttpNotFound()); } if (item.UserReviews == null) { item.UserReviews = new List <BlogReviewViewModel>(); } return(View(item)); }
public HttpResponseMessage FetchPosts(HttpRequestMessage request) { // this call is not used in the site since it's happening from the view-controller HttpResponseMessage response = null; try { IBlogPostRepository blogPostRepository = new BlogPostRepository("easyBlog"); IEnumerable <BlogPost> blogPosts = blogPostRepository.Get(); response = request.CreateResponse <BlogPost[]>(HttpStatusCode.OK, blogPosts.ToArray()); } catch (Exception ex) { response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } return(response); }
public virtual async Task <BlogPostDto> UpdateAsync(Guid id, UpdateBlogPostDto input) { var blogPost = await BlogPostRepository.GetAsync(id); blogPost.SetTitle(input.Title); blogPost.SetShortDescription(input.ShortDescription); blogPost.SetContent(input.Content); blogPost.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); if (blogPost.CoverImageMediaId != null && input.CoverImageMediaId == null) { await MediaDescriptorAdminAppService.DeleteAsync(blogPost.CoverImageMediaId.Value); } blogPost.CoverImageMediaId = input.CoverImageMediaId; if (blogPost.Slug != input.Slug) { await BlogPostManager.SetSlugUrlAsync(blogPost, input.Slug); } await BlogPostRepository.UpdateAsync(blogPost); return(ObjectMapper.Map <BlogPost, BlogPostDto>(blogPost)); }
public BlogPost GetBlogPost(int id) { var repo = new BlogPostRepository(_connectionString); return(repo.GetById(id)); }
public IActionResult Create(BlogPost newPost) { BlogPostRepository.AddPost(newPost, HttpContext.Session.GetString("Author")); return(RedirectToAction("Blogs")); }
public HomeController(BlogPostRepository blogPostRepository) { _blogPostRepository = blogPostRepository; }
public virtual async Task UpdateAsync(BlogPost blogPost) { await CheckBlogExistenceAsync(blogPost.BlogId); await BlogPostRepository.UpdateAsync(blogPost); }
public async Task <ActionResult> IndexAsync() { var items = await BlogPostRepository <BlogItemViewModel> .GetItemsAsync(); return(View(items)); }
public BlogPostController() { _repo = new BlogPostRepository(); }
public int GetTotalComments() { var repo = new BlogPostRepository(_connectionString); return(repo.GetTotalComments()); }
public async Task <CmsUserDto> GetAuthorHasBlogPostAsync(Guid id) { var author = await BlogPostRepository.GetAuthorHasBlogPostAsync(id); return(ObjectMapper.Map <CmsUser, CmsUserDto>(author)); }
public async Task <bool> HasBlogPostWaitingForReviewAsync() { return(await BlogPostRepository.HasBlogPostWaitingForReviewAsync()); }
public BloggingService(BlogPostRepository blogRepository, CategoryRepository categoryRepository) { _blogRepository = blogRepository; _categoryRepository = categoryRepository; }
/// <summary> /// Metodo para obtener todos los post creados /// </summary> /// <returns></returns> public List <BlogPost> GetAllPosts() { BlogPostRepository _repo = new BlogPostRepository(); return(_repo.GetAllPosts()); }
public List <Comment> GetComments(int blogPostId) { var repo = new BlogPostRepository(_connectionString); return(repo.GetComments(blogPostId)); }
public ActionResult Index(string author) { HttpContext.Session.SetString(SessionKeyName, author); return(View(BlogPostRepository.GetByAuthor(author))); }
public int GetMostRecent() { var repo = new BlogPostRepository(_connectionString); return(repo.GetMostRecent()); }
public virtual async Task DeleteAsync(Guid id) { await BlogPostRepository.DeleteAsync(id); }
public BlogPostOperations() { _repo = new BlogPostRepository(); }
public virtual async Task <BlogPostDto> GetAsync(Guid id) { var blogPost = await BlogPostRepository.GetAsync(id); return(ObjectMapper.Map <BlogPost, BlogPostDto>(blogPost)); }
public BlogPostController(AppDbContext context, ILogger <BlogPostController> logger, BlogPostRepository postRepository) : base(context, logger) { _postRepository = postRepository; _context = context; _logger = logger; }
public void StoreBlogPost() { var keywords = new HashSet<string> { "adorbs", "cheshire", "funny" }; var post = new BlogPost( "This one is so lulz!", "Cat Stevens", "Please check out these cat pics!", keywords, DateTime.Now, true); var repo = new BlogPostRepository(client, "cat_pics_quarterly"); string id = repo.Save(post); Assert.True(EnumerableUtil.NotNullOrEmpty((string)id)); Console.WriteLine("Blog post ID: {0}", id); }
public ActionResult Index() { return(View(BlogPostRepository.GetAllPosts())); }
public BlogPostsController(BlogPostRepository context) { _context = context; }