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); }
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>()); }
public static async Task <long> GetUsersMessageCount(string userId) { var messageCollection = await DocumentDBRepository <Message> .GetItemsAsync(message => message.Owner.Equals(userId)); return(messageCollection.Count()); }