public void SetPrivateProperties(PrivatePropertiesModel model, int id) { var existProperty = context.UserProperties.FirstOrDefault(x => x.UserId == id); if (existProperty == null) { context.UserProperties.Add(new UserProperty { UserId = id, ShowEmail = (bool)model.ShowEmail, ShowMobile = (bool)model.ShowMobile }); } else { existProperty.ShowEmail = model.ShowEmail; existProperty.ShowMobile = model.ShowMobile; } var existProfile = context.UserProfiles.FirstOrDefault(x => x.UserId == id); existProfile.Mobile = model.Mobile; context.SaveChanges(); }
public ActionResult EditPrivateProperties(PrivatePropertiesModel model) { repository.SetPrivateProperties(model, WebSecurity.CurrentUserId); return RedirectToAction("Index"); }
public PrivatePropertiesModel GetPrivateProperties(int id) { var model = new PrivatePropertiesModel(); var isExist = context .UserProperties .FirstOrDefault(x => x.UserId == id); if (isExist == null) { model.ShowEmail = model.ShowMobile = false; } else { model.ShowEmail = isExist.ShowEmail; model.ShowMobile = isExist.ShowMobile; } var mobile = context.UserProfiles.FirstOrDefault(x => x.UserId == id).Mobile; model.Mobile = mobile == null ? String.Empty : mobile; return model; }