public async Task <IDictionary <Guid, string> > GetRelatedLinkReadersAsync(Guid linkReaderId) { try { var result = new Dictionary <Guid, string>(); var linkReader = await Context.LinkReader.FirstOrDefaultAsync(p => p.LinkReaderId == linkReaderId); if (linkReader != null) { var linkReaderList = await Context.LinkReader.Where(p => p.UserId == linkReader.UserId) .Select(p => new { p.LinkReaderId, p.ChatId }) .ToListAsync(); await Task.WhenAll(linkReaderList.Select(async p => { var chat = await _chatBO.GetChatAsync(p.ChatId); result.Add(p.LinkReaderId, chat.Title); }).ToArray()); return(result); } else { throw new Exception(ExceptionResources.InvalidId); } } catch (Exception exception) { Logger.LogError(exception.Message); throw; } }
public async Task SendWelcomeMessageAsync(bool isPrivateChat, long chatId) { try { if (isPrivateChat) { var message = MessageResources.StartPrivate; var replyMarkup = new InlineKeyboardMarkup(new[] { new InlineKeyboardButton { Text = MessageResources.StartGroup, Url = Configuration.GetSection("AppConfiguration")["StartGroupUri"] }, new InlineKeyboardButton { Text = MessageResources.RateBot, Url = Configuration.GetSection("AppConfiguration")["RateBotUri"] } }); await BotClient.SendTextMessageAsync(chatId, message, ParseMode.Markdown, true, false, 0, replyMarkup); } else { var chat = await _chatBO.GetChatAsync(chatId); var message = string.Format(MessageResources.Start, chat.Title); var replyMarkup = new InlineKeyboardMarkup(new[] { new InlineKeyboardButton { Text = MessageResources.StartGroup, Url = Configuration.GetSection("AppConfiguration")["StartGroupUri"] }, new InlineKeyboardButton { Text = MessageResources.RateBot, Url = Configuration.GetSection("AppConfiguration")["RateBotUri"] } }); await BotClient.SendTextMessageAsync(chatId, message, ParseMode.Markdown, true, false, 0, replyMarkup); } } catch (Exception exception) { Logger.LogError(exception.Message); } }
public async Task <LinkResultDTO> GetAsync(LinkReader linkReader, bool isAPIRequest, string search, string user, DateTime?startDate, DateTime?endDate, int?pageIndex, int?pageSize) { try { if (!pageIndex.HasValue) { pageIndex = 0; } if (!pageSize.HasValue) { pageSize = 10; } if (!startDate.HasValue) { startDate = DateTime.Now.AddMonths(-1); } if (!endDate.HasValue) { endDate = DateTime.Now.AddDays(1).AddMilliseconds(-1); } else { endDate = endDate.Value.AddDays(1).AddMilliseconds(-1); } var searchQuery = Context.Link.Where(p => p.ChatId == linkReader.ChatId && (string.IsNullOrEmpty(search) || p.Message.Contains(search)) && (string.IsNullOrEmpty(user) || p.Username.Contains(user)) && (p.CreateDate >= startDate.Value) && (p.CreateDate <= endDate.Value) ).OrderByDescending(p => p.CreateDate); var totalItems = await Context.Link.Where(p => p.ChatId == linkReader.ChatId).CountAsync(); var totalSearchItems = await searchQuery.CountAsync(); var searchItems = await searchQuery.Skip(pageIndex.Value *pageSize.Value).Take(pageSize.Value).ToListAsync(); var chat = await _chatBO.GetChatAsync(linkReader.ChatId); var linkResultDTO = new LinkResultDTO { ChatId = linkReader.ChatId, ChatTitle = chat.Title, CreateDate = DateTime.Now, TotalItems = totalItems, TotalSearchItems = totalSearchItems, Items = new List <LinkDTO>() }; var userDataList = new List <Tuple <int, string, string> >(); foreach (var link in searchItems) { var linkDTO = new LinkDTO { Title = link.Title, CreateDate = link.CreateDate, Uri = link.Uri, Description = link.Description, Keywords = link.Keywords, ThumbnailUri = link.ThumbnailUri, UserId = link.UserId }; if (!string.IsNullOrEmpty(link.Username)) { linkDTO.Username = link.Username; } var linkUserData = userDataList.FirstOrDefault(p => p.Item1 == link.UserId); if (linkUserData != null) { if (!string.IsNullOrWhiteSpace(linkUserData.Item2)) { linkDTO.FirstName = linkUserData.Item2; } if (!string.IsNullOrWhiteSpace(linkUserData.Item3)) { linkDTO.LastName = linkUserData.Item3; } } else { var chatMember = await _chatBO.GetChatMemberAsync(linkReader.ChatId, link.UserId); if (chatMember != null && chatMember.User != null) { if (!string.IsNullOrWhiteSpace(chatMember.User.FirstName)) { linkDTO.FirstName = chatMember.User.FirstName; } if (!string.IsNullOrWhiteSpace(chatMember.User.LastName)) { linkDTO.LastName = chatMember.User.LastName; } var userData = new Tuple <int, string, string>(link.UserId, linkDTO.FirstName, linkDTO.LastName); userDataList.Add(userData); } } linkResultDTO.Items.Add(linkDTO); } await _linkReaderLogBO.SaveLogAsync(linkReader.LinkReaderId, isAPIRequest, searchItems.Count()); return(linkResultDTO); } catch (Exception exception) { Logger.LogError(exception.Message); throw; } }