public IActionResult Get(long id) { var blogPost = _posts.Find(id); if (blogPost == null) { return(NotFound()); } else { return(new ObjectResult(blogPost)); } }
public override IPost Update(IPost entity) { string CurrentUser = HttpContext.Current.User.Identity.GetUserId(); try { if (entity.Comments != null && entity.Comments.Count > 0) { var item = entity.Comments.ToList()[0]; CommentsBm comment = new CommentsBm(); comment.Id = item.Id; comment.Comentariu = item.Comentariu; comment.CreatedDate = DateTime.Now; comment.Id_Postare = item.Id_Postare; comment.Id_User = CurrentUser; unitOfWork.Comments.AddOrUpdate(_commentFactory.CopyTo(comment)); Commit(); } if (!entity.HasLike && entity.Likes.Count > 0) { var item = entity.Likes.ToList()[0]; if (unitOfWork.Likes.Find(x => x.Id == item.Id).Any()) { item.Id_User = CurrentUser; unitOfWork.Likes.Remove(_likeFactory.CopyTo(item)); Commit(); } } if (entity.HasLike && entity.Likes.Count > 0) { var item = entity.Likes.ToList()[0]; LikeBm like = new LikeBm(); like.Id = item.Id; like.Id_Postare = item.Id_Postare; like.CreatedDate = DateTime.Now; like.Id_User = CurrentUser; unitOfWork.Likes.AddOrUpdate(_likeFactory.CopyTo(like)); Commit(); } byte[] imageBytes = null; if (entity.Image != null) { imageBytes = FileHelper.ImageStringToByteArray(entity.Image.InputStream); entity.Imagine = imageBytes; } else { entity.Imagine = _postsRepository.Find(x => x.Id == entity.Id).FirstOrDefault().Imagine; } entity.IdUser = CurrentUser; _postsRepository.AddOrUpdate(_postsFactory.CopyTo(entity)); Commit(); return(entity); } catch (Exception ex) { // LogService.Log.Error(ex); } return(null); }
public SinglePost GetSingleById(string questionId) { var post = postsRepository.Find(questionId); var question = questionsElasticRepository.GetById(post.PostId); var answers = answerElasticRepository.GetAllByQuestionId(post.PostId).OrderByDescending(a => a.Score).ToList(); if (question.AcceptedAnswerId != null) { var acceptedIndex = answers.FindIndex(a => a.Id == question.AcceptedAnswerId.ToString()); if (acceptedIndex != -1) { answers.Move(acceptedIndex, 1, 0); } } return(new SinglePost() { Id = question.Id, Score = question.Score, AcceptedAnswerId = question.AcceptedAnswerId.ToString(), Answers = answers, Body = question.Body, CreationDate = question.CreationDate, FavoriteCount = question.FavoriteCount, Tags = question.Tags.Substring(1, question.Tags.Length - 2).Split("><"), Title = question.Title, ViewCount = question.ViewCount }); }
public Pager <PostItem> Posts(int take = 10, int skip = 0, string filter = "", string order = "") { return(_postsRepository.Find(take, skip)); }