public ActionResult Privacy() { Entities dbContext = new Entities(); Guid userGuid = new Guid(UserHelper.getLoggedInUserId()); UserPrivacy privacy = dbContext.UserPrivacies.SingleOrDefault(p => p.UserId == userGuid); if (privacy == null) { privacy = new UserPrivacy(); privacy.SeeMyInfo = 0; privacy.SeeMyWall = 0; privacy.SeeMyPhotos = 0; } var model = new PrivacyModel { SeeMyInfo = privacy.SeeMyInfo, SeeMyWall = privacy.SeeMyWall, SeeMyPhotos = privacy.SeeMyPhotos }; return View(model); }
/// <summary> /// Deprecated Method for adding a new object to the UserPrivacies EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUserPrivacies(UserPrivacy userPrivacy) { base.AddObject("UserPrivacies", userPrivacy); }
/// <summary> /// Create a new UserPrivacy object. /// </summary> /// <param name="userId">Initial value of the UserId property.</param> /// <param name="seeMyInfo">Initial value of the SeeMyInfo property.</param> /// <param name="seeMyWall">Initial value of the SeeMyWall property.</param> /// <param name="seeMyPhotos">Initial value of the SeeMyPhotos property.</param> public static UserPrivacy CreateUserPrivacy(global::System.Guid userId, global::System.Int32 seeMyInfo, global::System.Int32 seeMyWall, global::System.Int32 seeMyPhotos) { UserPrivacy userPrivacy = new UserPrivacy(); userPrivacy.UserId = userId; userPrivacy.SeeMyInfo = seeMyInfo; userPrivacy.SeeMyWall = seeMyWall; userPrivacy.SeeMyPhotos = seeMyPhotos; return userPrivacy; }
public ActionResult Privacy(PrivacyModel model) { ViewBag.message = null; if(ModelState.IsValid) { try { Entities dbContext = new Entities(); Guid userGuid = new Guid(UserHelper.getLoggedInUserId()); UserPrivacy privacy = dbContext.UserPrivacies.SingleOrDefault(p => p.UserId == userGuid); if (privacy == null) { privacy = new UserPrivacy(); privacy.UserId = userGuid; privacy.SeeMyInfo = model.SeeMyInfo; privacy.SeeMyWall = model.SeeMyWall; privacy.SeeMyPhotos = model.SeeMyPhotos; dbContext.UserPrivacies.AddObject(privacy); } else { privacy.SeeMyInfo = model.SeeMyInfo; privacy.SeeMyWall = model.SeeMyWall; privacy.SeeMyPhotos = model.SeeMyPhotos; } dbContext.SaveChanges(); ViewBag.message = "Your privacy settings were saved."; }catch(Exception ex) { ModelState.AddModelError("", ex.Message); } } return View(model); }