public static void CheckForAll(string email) { using (var db = new LanguageExchangeModel()) { var user = db.UserAccounts.Where(u => u.UserEmail == email).FirstOrDefault(); if (user == null) { return; } var userId = user.UserIdNumber; var pref = db.UserPreferences.Where(i => i.UserId == userId).FirstOrDefault(); if (pref == null) { pref = new UserPreferences(); pref.UserPreferencesName = user.UserFirstName + " " + user.UserLastName; pref.UserId = userId; pref.UserDescription = "Something interesting about me!"; pref.LastLogin = DateTime.Now; db.UserPreferences.Add(pref); } var calendar = db.AppointmentCalendars.Where(c => c.UserId == userId).FirstOrDefault(); if (calendar == null) { calendar = new AppointmentCalendar(); calendar.UserId = userId; db.AppointmentCalendars.Add(calendar); } var inbox = db.EmailInboxes.Where(i => i.UserId == userId).FirstOrDefault(); if (inbox == null) { inbox = new EmailInbox(); inbox.UserId = userId; db.EmailInboxes.Add(inbox); } var tracking = db.UserTrackingDetails.Where(t => t.UserId == userId).FirstOrDefault(); if (tracking == null) { tracking = new UserTrackingDetails(); tracking.UserId = userId; db.UserTrackingDetails.Add(tracking); } db.SaveChanges(); } }
public ActionResult Edit(UserPreferences prefs) { LanguageExchangeFactory.UpdateUserPreferences(User.Identity.Name, prefs); return RedirectToAction("Index"); }
public ActionResult Delete(UserPreferences prefs) { LanguageExchangeFactory.DeletePrefs(prefs); return RedirectToAction("Index"); }
public static UserPreferences ShowMyUserPreferences(string email) { var db = new LanguageExchangeModel(); var userAccount = db.UserAccounts.Where(u => u.UserEmail == email).FirstOrDefault(); var userId = userAccount.UserIdNumber; var pref = db.UserPreferences.Where(i => i.UserId == userId).FirstOrDefault(); if (pref == null) { pref = new UserPreferences(); pref.UserPreferencesName = userAccount.UserFirstName + " " + userAccount.UserLastName; pref.UserId = userId; pref.UserDescription = "Something interesting about me!"; pref.LastLogin = DateTime.Now; db.UserPreferences.Add(pref); db.SaveChanges(); } return pref; }
public static UserPreferences ShowUserPreferences (int userId) { var db = new LanguageExchangeModel(); var user = db.UserAccounts.Where(u => u.UserIdNumber == userId).FirstOrDefault(); var pref = db.UserPreferences.Where(i => i.UserId == userId).FirstOrDefault(); if (pref == null) { pref = new UserPreferences(); pref.UserPreferencesName = user.UserFirstName + " " + user.UserLastName; pref.UserId = userId; db.UserPreferences.Add(pref); db.SaveChanges(); } return pref; }
public static void UpdateUserPreferences(string email, UserPreferences updatedPreferences) { using (var db = new LanguageExchangeModel()) { var user = db.UserAccounts.Where(u => u.UserEmail == email).FirstOrDefault(); var pref = db.UserPreferences.Where(p => p.UserId == user.UserIdNumber).FirstOrDefault(); if (pref == null) { return; } var originalPrefs = pref; pref.UserPrimaryTeachingLanguage = updatedPreferences.UserPrimaryTeachingLanguage; pref.UserPrimaryLearningLanguage = updatedPreferences.UserPrimaryLearningLanguage; pref.UserOtherTeachingLanguage = updatedPreferences.UserOtherTeachingLanguage; pref.UserOtherLearningLanguage = updatedPreferences.UserOtherLearningLanguage; pref.UserSkype = updatedPreferences.UserSkype; pref.UserPrefersTalkOrText = updatedPreferences.UserPrefersTalkOrText; pref.UserTimeZone = updatedPreferences.UserTimeZone; pref.UserPhoto = updatedPreferences.UserPhoto; pref.UserDescription = updatedPreferences.UserDescription; pref.UserPreferencesName = updatedPreferences.UserPreferencesName; pref.UserCountry = updatedPreferences.UserCountry; db.Entry(originalPrefs).CurrentValues.SetValues(pref); db.SaveChanges(); } }
public static void DeletePrefs (UserPreferences prefs) { using (var db = new LanguageExchangeModel()) { db.UserPreferences.Remove(prefs); db.SaveChanges(); } }
public static void UpdateLastLoggedIn (string email) { using (var db = new LanguageExchangeModel()) { var user = db.UserAccounts.Where(u => u.UserEmail == email).FirstOrDefault(); if (user == null) { return; } var userId = user.UserIdNumber; var prefs = db.UserPreferences.Where(p => p.UserId == userId).FirstOrDefault(); if (prefs == null) { prefs = new UserPreferences(); prefs.UserId = userId; } prefs.LastLogin = DateTime.Now; db.SaveChanges(); } }