Ejemplo n.º 1
0
    public Post Save(Post post)
    {
        // Weird lame hack
        post.CategoryFk = post.Category.Id;
        post.Category   = null !;
        post.UserFk     = post.User.Id;
        post.User       = null !;

        var saved = context.Add(post);

        context.SaveChanges();
        return(saved.Entity);
    }
Ejemplo n.º 2
0
    public Comment SaveForPost(int postId, Comment comment)
    {
        comment.PostFk = postId;
        comment.Post   = null !;
        comment.UserFk = comment.User?.Id;
        comment.User   = null !;

        var saved = context.Add(comment);

        context.SaveChanges();
        saved.Entity.User =
            context.Users.Single(user => user.Id == comment.UserFk);
        return(saved.Entity);
    }