public static bool CanDeleteComment(CommentContract comment) { ParamIs.NotNull(() => comment); return(Manager.HasPermission(PermissionToken.DeleteComments) || (comment.Author != null && User != null && comment.Author.Id == User.Id)); }
public static CommentContract ConvertToCommentContract(Comment comment) { if (comment == null) { return(null); } CommentContract contractComment = new CommentContract() { CommentID = comment.CommentID, Comment1 = comment.Comment1, UserID = comment.UserID, ProfileID = comment.ProfileID, Date = comment.Date, }; return(contractComment); }
public CommentContract Create(CommentContract comment, int postId) { var p = _postRepository.GetSingle(postId); _repository.Insert(new Comment { SentBy = comment.SentBy, SentAt = comment.SentAt, Body = comment.Body, Post = p }); _repository.SaveChanges(); var added = _repository.GetSingle(comment.Id); comment.Id = added.Id; return(comment); }
public CommentContract Update(CommentContract comment) { var entity = _repository.GetSingle(comment.Id); entity.Body = comment.Body; entity.SentAt = comment.SentAt; _repository.Update(entity); _repository.SaveChanges(); return(new CommentContract { Id = entity.Id, SentBy = entity.SentBy, SentAt = entity.SentAt, Body = entity.Body }); }
public static CommentDto ToDto(this CommentContract contract) { if (contract == null) { return(null); } return(new CommentDto() { Date = contract.Date, Id = contract.Id, LikeCount = contract.LikeCount, PostId = contract.PostId, Text = contract.Text, UserId = contract.User.Id, UserName = contract.User.UserName, UserPic = contract.User.PicUrl }); }
public IEnumerable <CommentContract> GetAll() { var comments = _repository.GetAll(); var dto = new List <CommentContract>(); foreach (var comment in comments) { var p = new PostContract { Id = comment.Post.Id, SentBy = comment.Post.SentBy, SentAt = comment.Post.SentAt, Subject = comment.Post.Subject, Body = comment.Post.Body }; var c = new CommentContract { SentBy = comment.SentBy, SentAt = comment.SentAt, Body = comment.Body, Post = p }; dto.Add(c); } return(dto); }
public CommentViewModel(CommentContract comment, string targetName, string targetUrl) { Comment = comment; TargetName = targetName; TargetUrl = targetUrl; }
public async Task <CommentContract> Add(CommentContract contract) { var data = await _commentRepository.Add(Mapper.Map <Comment>(contract)); return(Mapper.Map <CommentContract>(data)); }