private Comment Map(CommentRecord rec) => factory.Create( rec.Id, rec.UserId, rec.PostId, rec.ParentId, rec.Body, new VoteStats(rec.Upvotes, rec.Downvotes), rec.CreationDate, rec.WasUpdated, rec.WasDeleted);
/// <summary> /// Delete an existing comment. /// </summary> /// <param name="entity">The comment to delete.</param> public async Task Delete(Comment entity) { CommentRecord commentRec = this.commentMapper.Reverse(entity).Item1; await Connection.ExecuteAsync(@"UPDATE Comment SET WasDeleted = TRUE Where Id = @Id", commentRec); entity.WasDeleted = true; }
/// <summary> /// Convert the entity back to it's row. /// </summary> /// <param name="destination">The post entity to convert.</param> /// <returns>The rebuilt record.</returns> public Tuple <CommentRecord, UserRecord> Reverse(Comment destination) { CommentRecord commentRec = new CommentRecord() { Id = destination.Id, UserId = destination.User.Id, PostId = destination.PostId, Body = destination.Body, CreationDate = destination.CreationDate, WasUpdated = destination.WasUpdated, WasDeleted = destination.WasDeleted, Upvotes = destination.Upvotes, Downvotes = destination.Downvotes }; //Comments dont always have a parent. if (destination.Parent != null) { commentRec.ParentId = destination.Parent.Id; } UserRecord userRec = this.userMapper.Reverse(destination.User); return(Tuple.Create(commentRec, userRec)); }
/// <summary> /// Add a new comment. /// </summary> /// <param name="entity">The comment to add.</param> public async Task Add(Comment entity) { CommentRecord commentRec = this.commentMapper.Reverse(entity).Item1; entity.Id = await Connection.QueryFirstOrDefaultAsync <int>( @"INSERT INTO Comment (UserId, PostId, ParentId, Body, CreationDate, WasUpdated, WasDeleted, Upvotes, Downvotes) VALUES (@UserId, @PostId, @ParentId, @Body, @CreationDate, @WasUpdated, @WasDeleted, @Upvotes, @Downvotes) RETURNING Id;", commentRec ); }
private CommentReadView Map(CommentRecord source) => new CommentReadView() { Id = source.Id, PostId = source.PostId, Body = source.Body, CreationDate = source.CreationDate, WasUpdated = source.WasUpdated, WasDeleted = source.WasDeleted, Upvotes = source.Upvotes, Downvotes = source.Downvotes };
/// <summary> /// Update an existing comment. /// </summary> /// <param name="entity">The comment to update.</param> public async Task Update(Comment entity) { CommentRecord commentRec = this.commentMapper.Reverse(entity).Item1; await Connection.ExecuteAsync( @"UPDATE Comment SET UserId = @UserId, PostId = @PostId, ParentId = @ParentId, Body = @Body, CreationDate = @CreationDate, WasUpdated = @WasUpdated, WasDeleted = @WasDeleted, Upvotes = @Upvotes, Downvotes = @Downvotes WHERE Id = @Id", commentRec ); entity.WasUpdated = true; }
private Comment Mapper(CommentRecord commentRec, UserRecord userRec) => this.commentMapper.Map(Tuple.Create(commentRec, userRec));