public static void MigrateXmlDataToDatabase() { var friendList = BirthdayUtility.GetFriendBirthdayList(); if (friendList != null && friendList.Count > 0) { using (var context = new BirthdayDataContext(Database.DbConnectionString)) { foreach (var friend in friendList) { var dbFriend = new FriendEntity { BigProfilePictureUrl = friend.BigProfilePictureUrl, Birthday = string.IsNullOrEmpty(friend.Birthday) ? new DateTime?() : Convert.ToDateTime(friend.Birthday), Email = friend.Email, FacebookId = friend.Email, IsReminderCreated = false, IsHidden = friend.isHidden, LastToastRaisedYear = friend.LastToastRaisedYear, Name = friend.Name, PhoneNumber = friend.PhoneNumber, ProfilePictureLocation = friend.ProfilePictureLocation, ProfilePictureUrl = friend.ProfilePictureUrl, SendAutoEmailOnBirthday = friend.SendAutoEmailOnBirthday, TypeOfContact = friend.TypeOfContact }; context.Friends.InsertOnSubmit(dbFriend); } context.SubmitChanges(); } } CleanUpOldFiles(); }
/// <summary> /// Save the ocal cards to file /// </summary> public static void SaveLocalCards() { using (var context = new BirthdayDataContext(Database.DbConnectionString)) { if (context.Cards.Any()) return; var cards = new List<CardEntity> { new CardEntity{Url = "http://www.simmsmanncenter.ucla.edu/wp-content/uploads/30420-birthday-candles1.jpg"}, new CardEntity{Url = "http://images.thefuntimesguide.com/wp-content/blogs.dir/46/files/strawberry-birthday-cake-by-chidorian-thumb-280x278-10085.jpg"} } .AsEnumerable(); context.Cards.InsertAllOnSubmit(cards); context.SubmitChanges(); } }
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(); } }
/// <summary> /// Deletes a specific card /// </summary> /// <param name="id">Id of the card to be deleted</param> public static void DeleteCard(int id) { using (var context = new BirthdayDataContext(Database.DbConnectionString)) { context.Cards.DeleteOnSubmit(GetBirthdayCardById(id)); context.SubmitChanges(); } }
public static void DeleteCards(List<int> cardIds) { using (var context = new BirthdayDataContext(Database.DbConnectionString)) { var cardsToDelete = (from card in context.Cards where cardIds.Contains(card.Id) select card).AsEnumerable(); context.Cards.DeleteAllOnSubmit(cardsToDelete); context.SubmitChanges(); } }
public static void UpdateUrlInCard(int id, string url) { using (var context = new BirthdayDataContext(Database.DbConnectionString)) { var existingCard = (from card in context.Cards where card.Id == id select card).Single(); existingCard.Url = url; context.SubmitChanges(); } }
public static void AddBirthdayCard(CardEntity newCard) { using (var context = new BirthdayDataContext(Database.DbConnectionString)) { context.Cards.InsertOnSubmit(newCard); context.SubmitChanges(); } }
/// <summary> /// Hides a friend record from display /// </summary> /// <param name="friendId">ID of the friend</param> public static void DeleteFriend(int friendId) { using (var context = new BirthdayDataContext(Database.DbConnectionString)) { var friendToDelete = (from friend in context.Friends where friend.UniqueId == friendId select friend).Single(); friendToDelete.IsHidden = true; context.SubmitChanges(); } }
/// <summary> /// Add a new friend /// </summary> /// <param name="friendDetails">The details of the friend to be added</param> /// <returns>The Guid of the new friend</returns> public static int AddNewFriend(FriendEntity friendDetails) { using (var context =new BirthdayDataContext(Database.DbConnectionString)) { friendDetails.SendAutoEmailOnBirthday = true; friendDetails.IsReminderCreated = false; friendDetails.IsHidden = false; friendDetails.LastToastRaisedYear = 1900; context.Friends.InsertOnSubmit(friendDetails); context.SubmitChanges(); return friendDetails.UniqueId; } }
/// <summary> /// Updates the details of a particulat friend /// </summary> /// <param name="friendDetails">The details of the friend to update</param> public static void UpdateFriendDetails(FriendEntity friendDetails) { using (var context = new BirthdayDataContext(Database.DbConnectionString)) { var existingFriend = (from friend in context.Friends where friend.UniqueId == friendDetails.UniqueId select friend).FirstOrDefault(); CopyProperties(existingFriend, friendDetails); //considering the scenario where the data should be automatically updated as reference has been updated context.SubmitChanges(); } }