public async Task <UserProfileMold> Get(GetProfile request) { var user = await RavenSession.LoadAsync <User>(request.UserId); var mapped = Mapper.Map <UserProfileMold>(user); return(mapped); }
public async Task <MessagePage> Get(GetMessages request) { var messages = RavenSession.Query <Message>().Where(e => e.ChatId == request.ChatId).OrderByDescending(x => x.PostTime); var result = new MessagePage(); if (request.BeforePostTime != null) { messages = messages.Where(x => x.PostTime.UtcDateTime < request.BeforePostTime.Value.UtcDateTime); } var pageSize = request.PageSize ?? 10; var docs = await messages.Take(pageSize) .Include(x => x.UserId) .Include(s => s.Attachments) .ToListAsync(); result.Messages = new List <MessageMold>(); foreach (var doc in docs) { var user = await RavenSession.LoadAsync <User>(doc.UserId); var message = Mapper.Map <MessageMold>(doc); if (doc.Attachments != null) { var attach = await RavenSession.LoadAsync <Attachment>(doc.Attachments); message.Attachments = new List <AttachmentMold>(); foreach (var id in doc.Attachments) { if (attach.TryGetValue(id, out var attachment)) { message.Attachments.Add(Mapper.Map <AttachmentMold>(attachment)); } //TODO учесть в будущем показ потерянных файлов } } if (user != null) { message.UserNickName = string.IsNullOrWhiteSpace(user.DisplayName) ? user.Login : user.DisplayName; } result.Messages.Add(message); } return(result); }
private async Task <User> GetUserById(string uid) { return(await RavenSession.LoadAsync <User>(uid, b => b.IncludeDocuments(uid + SecretPostfix))); }
private async Task <UserSecret> GetUserSecret(string uid) { var secret = await RavenSession.LoadAsync <UserSecret>(uid + SecretPostfix); return(secret); }