Example #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,
                };
            }
        }
Example #2
0
        public void Unsubscribe(Guid channelId, Guid userId)
        {
            using (var ctx = new SkillSharingContext())
            {
                var user = ctx.Users.Single(x => x.Id == userId);
                var channel = user.Channels.SingleOrDefault(x => x.Id == channelId);

                user.Channels.Remove(channel);
                ctx.SaveChanges();
            }
        }
Example #3
0
        public void UpdateState(PostState postState)
        {
            using (var ctx = new SkillSharingContext())
            {
                var state = ctx.PostStates.SingleOrDefault(x => x.Id == postState.Id && x.UserId == postState.UserId);
                if (state == null)
                {
                    state = new PostState
                    {
                        Id = Guid.NewGuid(),
                        PostId = postState.PostId,
                        UserId = postState.UserId
                    };
                    ctx.PostStates.Add(state);
                }

                state.IsTodo = postState.IsTodo;
                state.IsDone = postState.IsDone;
                state.IsHidden = postState.IsHidden;

                ctx.SaveChanges();
            }
        }