public ActionResult SaveUserSignatures(User user) { int membershipId = -1; if (Auth.IsAuthenticated(Request, User, out membershipId)) //if (IsAuthenticated(out membershipId)) { bool newRecord = true; var existUserData = (from s in _db.Users where s.MembershipId == membershipId select s).SingleOrDefault<User>(); if (existUserData == null) { existUserData = user; } else { newRecord = false; existUserData.Phone1 = user.Phone1; existUserData.Phone2 = user.Phone2; existUserData.Phone3 = user.Phone3; existUserData.url = user.url; existUserData.UserName = user.UserName; existUserData.ApplyToAd = user.ApplyToAd; } existUserData.MembershipId = membershipId; if (newRecord) _db.Users.Add(existUserData); else { _db.Users.Attach(existUserData); _db.Entry(existUserData).State = EntityState.Modified; } _db.SaveChanges(); return RedirectToAction("index", "PrivateRoom"); } return RedirectToAction("index", "home"); }
private RealtyDomainObjects.User AddNewUserIfNotExist(RealtyDomainObjects.PropertyObject po) { int membershipId = -1; RealtyDomainObjects.User user = null; if (Auth.IsAuthenticated(Request, User, out membershipId)) { user = (from s in _db.Users where s.MembershipId == membershipId select s).SingleOrDefault<RealtyDomainObjects.User>(); if (user == null) { user = new RealtyDomainObjects.User() { MembershipId = membershipId, Phone1 = po.Phone1, Phone2 = po.Phone2, Phone3 = po.Phone3, url = po.SourceUrl, UserName = po.ContactName }; _db.Users.Add(user); _db.SaveChanges(); } } return user; }