public ActionResult UserSet(UserSetModel model) { UserNumber me = db.UserNumbers.Find(User.Identity.Name); me.RelName = model.RealName; if (model.Cologe > 0) { Coloege c = db.Coloeges.Find(model.Cologe); if (c != null) { me.Coloege = c; } } me.Gender = model.Grade; me.Class = model.Grade2; if (model.Label?.Length > 1) { me.Labels = model.Label.Substring(1); } db.Entry(me).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Session["UserSet"] = "信息保存成功!页面部分显示信息可能在重新登陆后才能更新生效"; ViewBag.Msg = "信息保存成功!页面部分显示信息可能在重新登陆后才能更新生效"; return(RedirectToAction("UserSet")); }
public ActionResult UserSet() { AppUser appUser = UserManager.FindById(User.Identity.GetUserId()); UserNumber u = db.UserNumbers.Find(User.Identity.Name); UserSetModel model = new UserSetModel(); if (u != null) { model.Email = appUser.Email; model.Phone = appUser.PhoneNumber; model.RealName = u.RelName; model.Cologe = u.Coloege == null?0: u.Coloege.Id; model.Grade = (int)u.Gender; model.Grade2 = u.Class; } model.Labels = new List <string>(); if (!string.IsNullOrEmpty(u.Labels)) { model.Labels = u.Labels.Split(',').ToList(); } model.Cologes = db.Coloeges.ToList(); if (Session["UserSet"] != null) { ViewBag.Msg = Session["UserSet"].ToString(); Session["UserSet"] = null; } return(View(model)); }