protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            sallemContext context = new sallemContext();

            DomainManager = new EntityDomainManager <TodoItem>(context, Request);
        }
Example #2
0
        private async Task <Friendship> LocalUpdate(string id, Delta <Friendship> patch)
        {
            Friendship    updatable = patch.GetEntity();
            sallemContext context   = new sallemContext();
            var           friends   = context.Friendships;
            var           friendOne = friends.Where(x => x.Id == id && x.FriendId == updatable.FriendId).FirstOrDefault();
            var           friendTwo = friends.Where(x => x.Id == updatable.FriendId && x.FriendId == id).SingleOrDefault();

            if (friendOne != null) //Update first part of friendship
            {
                friendOne.StatusId  = updatable.StatusId;
                friendOne.UpdatedAt = DateTime.Now;
            }
            if (friendTwo != null) //Update second part of friendship
            {
                friendTwo.StatusId  = updatable.StatusId;
                friendTwo.UpdatedAt = DateTime.Now;
            }
            await context.SaveChangesAsync();

            return(friendOne);
        }
        private async Task <List <FriendPost> > GetFriendsPostsSync(string id)
        {
            List <FriendPost> friendsPosts = new List <FriendPost>();

            try
            {
                string        i       = id;
                sallemContext context = new sallemContext();

                var friends = await context.Friendships.Where(x => x.Id == i &&
                                                              x.StatusId == 2
                                                              ).Select(x => x.FriendId).ToListAsync();

                friends.Add(id);
                var posts = await context.Posts.Where
                                (x => friends.Contains(x.UserId)).ToListAsync();

                foreach (var item in posts)
                {
                    FriendPost friendPost = new FriendPost();
                    friendPost.Id         = item.Id;
                    friendPost.PostedAt   = item.PostedAt;
                    friendPost.Subject    = item.Subject;
                    friendPost.UserId     = item.UserId;
                    friendPost.ImagePath  = item.ImagePath;
                    friendPost.ActivityId = item.ActivityId;
                    friendsPosts.Add(friendPost);
                }
                return(friendsPosts);
            }
            catch (System.Exception e)
            {
                string m = e.Message;
                throw;
            }
        }