public static async Task SyncCards(string userId) { var service = new AzureStorageService(Services.AzureConnectionString, userId); var onlineCards = (await service.GetBirthdayCards()).ToList(); var storedCards = GetBirthdayCards(); var nonExistentCards = onlineCards.Where(c => storedCards.All(sc => sc.Id != c.Id)); using (var context = new BirthdayDataContext(Database.DbConnectionString)) { context.Cards.InsertAllOnSubmit(nonExistentCards); context.SubmitChanges(); } }
private async void UploadImageToServer(String userId, String fileName, FileStream imageStream) { try { var service = new AzureStorageService(Services.AzureConnectionString, userId); var status = await service.SaveFileToBlob(fileName, imageStream); if (status.IsSuccess) { var url = Services.CardBaseUrl + userId + "/" + fileName; var newCard = new CardEntity { Url = url }; BirthdayUtility.AddBirthdayCard(newCard); var birthdays = DataContext as Birthdays; if (birthdays != null) birthdays.BirthdayCards.Add(newCard); } else { MessageBox.Show(status.ErrorMessage, AppResources.ErrAddCard, MessageBoxButton.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppResources.ErrAddCard, MessageBoxButton.OK); } }
private void DeleteAppBarClick(object sender, EventArgs e) { try { if (App.IsTrial) { //messagebox to prompt to buy var buyAppForDeleteMessageBox = new CustomMessageBox { Height = 300, Caption = AppResources.BuyFullVersion, Message = AppResources.BuyAppForDelete, LeftButtonContent = AppResources.BuyLabel, RightButtonContent = AppResources.LaterLabel, VerticalAlignment = VerticalAlignment.Center }; buyAppForDeleteMessageBox.Dismissed += BuyAppForDeleteMessageBoxDismissed; buyAppForDeleteMessageBox.Show(); return; } //display warning for confirmation var result = MessageBox.Show(AppResources.DeleteConfirmMessage, AppResources.DeleteLabel, MessageBoxButton.OKCancel); if (!result.Equals(MessageBoxResult.OK)) return; //check which list is active if (MainPagePanorama.SelectedItem.Equals(MostRecentPanorama)) { if (RecentBirthdayList != null && RecentBirthdayList.SelectedItems != null && RecentBirthdayList.SelectedItems.Count > 0) { foreach (FriendBirthday friend in RecentBirthdayList.SelectedItems) { BirthdayUtility.DeleteFriend(friend.Id); } } else { MessageBox.Show(AppResources.WarnSelectItem, AppResources.WarnTryAgain, MessageBoxButton.OK); } BindDataContext(); } else if (MainPagePanorama.SelectedItem.Equals(AllItemPanorama)) { if (AllBirthdayList != null && AllBirthdayList.SelectedItems != null && AllBirthdayList.SelectedItems.Count > 0) { foreach (FriendBirthday friend in AllBirthdayList.SelectedItems) { BirthdayUtility.DeleteFriend(friend.Id); } } else { MessageBox.Show(AppResources.WarnSelectItem, AppResources.WarnTryAgain, MessageBoxButton.OK); } BindDataContext(); } else if (MainPagePanorama.SelectedItem.Equals(BirthdayCardPanorama)) { //if image upload/delete is complete if (NetworkInterface.GetIsNetworkAvailable()) { if (BirthdayCardList != null && BirthdayCardList.SelectedItems != null && BirthdayCardList.SelectedItems.Count > 0) { var service = new AzureStorageService(Services.AzureConnectionString, App.UserPreferences.UserDetails.FacebookId); var items = BirthdayCardList.SelectedItems; var deletedCards = new List<int>(); if (items != null) { foreach (var cardEntity in items.Cast<CardEntity>()) { service.DeleteBlob(Path.GetFileName(cardEntity.Url)); deletedCards.Add(cardEntity.Id); } } var birthdays = DataContext as Birthdays; if (birthdays == null) return; var birthdayCards = birthdays.BirthdayCards; foreach (var cardId in deletedCards) { birthdayCards.Remove(birthdayCards.Single(c => c.Id == cardId)); } //remove entry fromm database BirthdayUtility.DeleteCards(deletedCards); } else { MessageBox.Show(AppResources.WarnSelectItem, AppResources.WarnTryAgain, MessageBoxButton.OK); } } else { MessageBox.Show(AppResources.WarnInternetMsg, AppResources.WarnNwTitle, MessageBoxButton.OK); } } } catch (Exception ex) { MessageBox.Show(ex.Message, AppResources.ErrDeleting, MessageBoxButton.OK); } }