Beispiel #1
0
        /// <summary>
        /// Add a post to the database.
        /// </summary>
        /// <param name="post">The post to add.</param>
        public async Task Add(Post post)
        {
            PostRecord rec = _postMapper.Reverse(post).Item1;

            post.Id = await Connection.QueryFirstOrDefaultAsync <int>(
                @"INSERT INTO Post 
                    (Title, Body, Type, CreationDate, UserId, SpaceId, WasUpdated, WasDeleted, CommentCount, Upvotes, Downvotes) 
                    VALUES 
                    (@Title, @Body, @Type, @CreationDate, @UserId, @SpaceId, @WasUpdated, @WasDeleted, @CommentCount, @Upvotes, @Downvotes) RETURNING Id;",
                rec
                );
        }
Beispiel #2
0
 private PostReadView Map(PostRecord source) => new PostReadView()
 {
     Id           = source.Id,
     Type         = source.Type,
     Title        = source.Title,
     Body         = source.Body,
     CreationDate = source.CreationDate,
     WasUpdated   = source.WasUpdated,
     WasDeleted   = source.WasUpdated,
     Upvotes      = source.Upvotes,
     Downvotes    = source.Downvotes
 };
Beispiel #3
0
        /// <summary>
        /// Convert the post back into it's record form.
        /// </summary>
        /// <param name="destination">The entity/</param>
        /// <returns>The rebuilt record.</returns>
        public Tuple <PostRecord, UserRecord, Tuple <SpaceRecord, UserRecord> > Reverse(Post destination)
        {
            PostRecord p = new PostRecord {
                Id           = destination.Id,
                UserId       = destination.User.Id,
                Type         = destination.Type,
                Title        = destination.Title,
                Body         = destination.Body,
                CreationDate = destination.CreationDate,
                WasUpdated   = destination.WasUpdated,
                WasDeleted   = destination.WasDeleted,
                CommentCount = destination.CommentCount,
                Upvotes      = destination.Upvotes,
                Downvotes    = destination.Downvotes,
                SpaceId      = destination.Space.Id
            };

            UserRecord u = userMapper.Reverse(destination.User);
            Tuple <SpaceRecord, UserRecord> s = spaceMapper.Reverse(destination.Space);

            return(Tuple.Create(p, u, s));
        }
Beispiel #4
0
 private Post Map(PostRecord rec) => factory.Create(rec.Id, rec.UserId, rec.SpaceId, rec.Type, rec.Title, rec.Body, rec.CreationDate, rec.CommentCount, rec.Upvotes, rec.Downvotes, rec.WasUpdated, rec.WasDeleted);