public bool EditProfile(string username, string email, string phone, List <string> regions_name, List <string> regions_value, List <bool> regions_limited) { var user = GetProfileByUsername(username); user.Email = email; user.Phone = phone; /*kill current regions*/ var regions = _context.UserProfileRegions.Where(upr => upr.User.UserName == username).ToList(); foreach (var region in regions) { _context.UserProfileRegions.Remove(region); } /*create new regions*/ for (int i = 0; i < regions_name.Count; i++) { if (regions_name[i] != "" && regions_value[i] != "") { _context.UserProfileRegions.Add(new UserProfileRegion() { Audience = regions_limited[i] ? Audience.Friends : Audience.Public, Name = regions_name[i], User = user, Value = regions_value[i] }); } } _context.SaveChanges(); return(true); }
public void StoreGeolocation(string ip, decimal longitude, decimal latitude, string username = null) { _context.Geolocations.Add(new Geolocation() { Ip = ip, Longitude = longitude, Latitude = latitude, User = (username == null) ? null : _context.UserProfiles.First(up => up.UserName == username), Time = DateTime.UtcNow }); _context.SaveChanges(); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (WayfarerContext db = new WayfarerContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }