public IEnumerable<OrgStructure> GetAll(Guid userId)
 {
     using (var ctx = new SkillSharingContext())
     {
         return ctx.Users.Single(x => x.Id == userId).OrgStructures.ToList();
     }
 }
Example #2
0
 public IEnumerable<PostState> GetByOrgStructure(Guid orgStructureId, Guid userId)
 {
     using (var ctx = new SkillSharingContext())
     {
         return ctx.OrgStructures.Single(x => x.Id == orgStructureId).Channels.SelectMany(x => x.Posts).Select(x => GetPostState(x, userId)).ToList();
     }
 }
Example #3
0
 public IEnumerable<PostState> GetAllTodo(Guid userId)
 {
     using (var ctx = new SkillSharingContext())
     {
         return ctx.PostStates.Where(x => !x.IsHidden && x.IsTodo && x.User.Id == userId).Include(x => x.Post).ToList();
     }
 }
Example #4
0
 public IEnumerable<PostState> GetByChannel(Guid channelId, Guid userId)
 {
     using (var ctx = new SkillSharingContext())
     {
         return ctx.Channels.Single(x => x.Id == channelId).Posts.Select(x => GetPostState(x, userId)).ToList();
     }
 }
Example #5
0
 public IEnumerable<PostState> GetAll(Guid userId)
 {
     using (var ctx = new SkillSharingContext())
     {
         return ctx.Users.Single(x => x.Id == userId).Channels.SelectMany(x => x.Posts).Select(x => GetPostState(x, userId)).ToList();
     }
 }
Example #6
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 #7
0
 public IEnumerable<Channel> GetAllSubscribed(Guid userId)
 {
     using (var ctx = new SkillSharingContext())
     {
         return ctx.Users.Single(x => x.Id == userId).Channels.ToList();
     }
 }
Example #8
0
 public IEnumerable<Channel> GetAll()
 {
     using (var ctx = new SkillSharingContext())
     {
         return ctx.Channels.ToList();
     }
 }
Example #9
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 #10
0
 public UserDto GetCurrent()
 {
     using (var ctx = new SkillSharingContext())
     {
         var user = ctx.Users.Single();
         var dto = new UserDto
         {
             Id = user.Id,
             FirstName = user.FirstName,
             LastName = user.LastName,
             Mail = user.Mail
         };
         UserSession.UserId = dto.Id;
         return dto;
     }
 }
Example #11
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();
            }
        }