예제 #1
0
        public static async Task <User> AddOrUpdateCurrentUser()
        {
            string email = ClaimsPrincipal.Current.FindFirst("preferred_username")?.Value;
            var    users = await DocumentDBRepository <User> .GetItemsAsync(u => u.Email.Equals(email));

            var user = users.FirstOrDefault();

            if (null != user)
            {
                var result = await DocumentDBRepository <User> .UpdateItemAsync(user.Id, user);
            }
            else
            {
                user = new User()
                {
                    Id    = Guid.NewGuid().ToString(),
                    Email = email
                };
                await DocumentDBRepository <User> .CreateItemAsync(user);
            }

            return(user);
        }
예제 #2
0
        public static async Task <List <Message> > GetUsersMessages(string userId, int pageSize, int pageNum)
        {
            var messageCollection = await DocumentDBRepository <Message> .GetItemsAsync(message => message.Owner.Equals(userId));

            return(messageCollection.OrderByDescending(x => x.ReceivedDateTime).Skip((pageNum - 1) * pageSize).Take(pageSize).ToList <Message>());
        }
예제 #3
0
        public static async Task <long> GetUsersMessageCount(string userId)
        {
            var messageCollection = await DocumentDBRepository <Message> .GetItemsAsync(message => message.Owner.Equals(userId));

            return(messageCollection.Count());
        }