public ActionResult ModifyUser() { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.SysUser.Modify(); vm.SexList = Dict.Controllers.DictSexController.SelectList(); var tb = (from p in db.Table <Sys.Entity.tbSysUser>() where p.Id == Code.Common.UserId select new Dto.SysUser.Modify { Email = p.Email, IdentityNumber = p.IdentityNumber, Mobile = p.Mobile, Qq = p.Qq, SexId = p.tbSex.Id, UserCode = p.UserCode, UserName = p.UserName, Photo = p.Photo }).FirstOrDefault(); if (tb != null) { vm.UserModify = tb; } return(View(vm)); } }
public ActionResult ModifyUser(Models.SysUser.Modify vm) { using (var db = new XkSystem.Models.DbContext()) { var error = new List <string>(); if (error.Count == decimal.Zero) { var file = Request.Files["UserModify.Photo"]; if (Code.Common.GetFileType(file.FileName) != Code.FileType.Image) { return(Content("<script >alert('图片格式必须是jpg、jpeg、png、bmp格式!');history.go(-1);</script >", "text/html")); } var tb = (from p in db.Table <Sys.Entity.tbSysUser>() .Include(d => d.tbSex) where p.Id == Code.Common.UserId select p).FirstOrDefault(); if (tb != null) { tb.tbSex = db.Set <Dict.Entity.tbDictSex>().Find(vm.UserModify.SexId); tb.IdentityNumber = vm.UserModify.IdentityNumber; tb.Email = vm.UserModify.Email; tb.Mobile = vm.UserModify.Mobile; tb.Qq = vm.UserModify.Qq; if (file.ContentLength > 0) { var fileSave = Server.MapPath("~/Files/UserPhoto/"); Random r = new Random(); var fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + r.Next(10000, 99999).ToString() + "." + file.FileName.Split('.').Last(); file.SaveAs(fileSave + fileName); tb.Photo = fileName; } if (db.SaveChanges() > 0) { vm.Status = true; XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改了个人用户信息"); } } else { error.AddError(Resources.LocalizedText.MsgNotFound); } } return(View(vm)); } }