Пример #1
0
        public PostState Create(string name, string content, bool isSticky, Guid userId, Guid channelId)
        {
            var post = new Post
            {
                Id = Guid.NewGuid(),
                Name = name,
                IsSticky = isSticky,
                Content = content,
                Timestamp = DateTime.Now,
                PublisherId = userId,
                ChannelId = channelId
            };

            using (var ctx = new SkillSharingContext())
            {
                ctx.Posts.Add(post);
                ctx.SaveChanges();
                return new PostState
                {
                    Id = Guid.NewGuid(),
                    UserId = userId,
                    Post = post,
                };
            }
        }
Пример #2
0
 private PostState GetPostState(Post post, Guid userId)
 {
     var state = post.PostStates.FirstOrDefault(s => s.UserId == userId && s.PostId == post.Id);
     return state ?? new PostState
     {
         Id = Guid.NewGuid(),
         User = new User { Id = userId },
         Post = post
     };
 }