private void AddNotificationDetailsToDatabase(NotificationForm state) { DateTime date = DateTime.Parse(state.Date); User user; using (var repository = new ChatBotRepository <User>()) { user = repository.GetSender(_user.ConversationId, _user.ToName); user.MediaElements = null; user.Notifications = null; } using (var repository = new ChatBotRepository <Notification>()) { var notification = new Notification { Date = date, Description = state.Description, UserId = user.Id }; repository.Create(notification); notification.User = user; RunScheduller(notification); } }
private IEnumerable <string> GetMediaElementsNames() { using (var repository = new ChatBotRepository <User>()) { return(repository.GetSender(_user.ConversationId, _user.ToName).MediaElements.Select(x => x.Name)); } }
private MediaElement SearchAttachmentsByName(IMessageActivity message) { MediaElement result; using (var repository = new ChatBotRepository <User>()) { result = repository.GetSender(_user.ConversationId, _user.ToName).MediaElements .FirstOrDefault(x => message.Text.ToLower() == x.Name.ToLower()); } return(result); }
private IEnumerable <MediaElement> SearchAttachmentsByTag(IMessageActivity message) { var tags = message.Text.Split(new char[] { ',', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries); IEnumerable <MediaElement> result; using (var repository = new ChatBotRepository <User>()) { result = repository.GetSender(_user.ConversationId, _user.ToName).MediaElements .Where(x => tags.Any(t => x.Tag.ToLower().Contains(t.ToLower()))); } return(result); }
private async Task SaveAttachmentToRepository(IMessageActivity message) { var attachment = message.Attachments.First(); using (HttpClient httpClient = new HttpClient()) { if ((message.ChannelId.Equals("skype", StringComparison.InvariantCultureIgnoreCase) || message.ChannelId.Equals("msteams", StringComparison.InvariantCultureIgnoreCase)) && new Uri(attachment.ContentUrl).Host.EndsWith("skype.com")) { var token = await new MicrosoftAppCredentials().GetTokenAsync(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); } var responseMessage = await httpClient.GetAsync(attachment.ContentUrl); var attachmentsInBytes = await responseMessage.Content.ReadAsByteArrayAsync(); var imageData = Convert.ToBase64String(attachmentsInBytes); var mediaElement = new MediaElement { ContentData = await responseMessage.Content.ReadAsByteArrayAsync(), ContentType = attachment.ContentType, Tag = _state.Tag, Name = attachment.Name, Description = _state.Description }; int userId; using (var repository = new ChatBotRepository <User>()) { userId = repository.GetSender(_user.ConversationId, _user.ToName).Id; } using (var repository = new ChatBotRepository <MediaElement>()) { mediaElement.UserId = userId; repository.Create(mediaElement); } } }
private string RemoveMediaElementFromDatabase(string name) { int?mediaItemId; using (var repository = new ChatBotRepository <User>()) { mediaItemId = repository.GetSender(_user.ConversationId, _user.ToName).MediaElements.FirstOrDefault(x => x.Name == name)?.Id; } using (var repository = new ChatBotRepository <MediaElement>()) { if (mediaItemId == null) { return("Упс, но такого файла нет в базе"); } var mediaItem = repository.FindById((int)mediaItemId); repository.Remove(mediaItem); return("Удаление прошо успешно, поздравляю(party)"); } }
private User GetCurrentUser(User user) { if (user == null) { return(null); } User result; using (var repository = new ChatBotRepository <User>()) { result = repository.GetSender(user.ConversationId, user.ToName); if (result == null) { repository.Create(user); result = user; } return(result); } }