public ActionResult UserEdit(NewsUser user, HttpPostedFileBase ENewsUserImage) { if (ENewsUserImage != null) { //拿到图片名称 string fileName = Path.GetFileName(ENewsUserImage.FileName); //判断文件是否是图片 //string hz = Path.GetExtension(fileName);//.jpg if (fileName.EndsWith("jpg") || fileName.EndsWith("png") || fileName.EndsWith("gif") || fileName.EndsWith("jpeg") || fileName.EndsWith("JPG") || fileName.EndsWith("PNG") || fileName.EndsWith("GIF") || fileName.EndsWith("JPEG")) { //保存图片到项目文件夹中 ENewsUserImage.SaveAs(Server.MapPath("~/Content/imageKeHu/User/" + fileName)); //将图片文件名,绑定到该用户的Photo user.NewsUserImage = fileName; } else { return(Content("<script>alert('图片格式错误');history.go(-1);</script>")); } } db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Session["userLogin"] = user; return(RedirectToAction("UserXiangxiKeHu", "UserVNKH", new { UserID = user.NewsUserID })); }
public ActionResult LoginUser(NewsUser nuser) { NewsUser newsuser = db.NewsUser.Where(a => a.NewsUserAccount == nuser.NewsUserAccount && a.NewsUserPwd == nuser.NewsUserPwd).FirstOrDefault(); if (newsuser == null) { ViewBag.tishi = "账号或密码错误"; return(View()); } else { Session["userLogin"] = newsuser; return(RedirectToAction("Index", "NewsVNKH")); } }
public ActionResult RegisterUser(NewsUser nuser) { NewsUser newsuser = db.NewsUser.Where(a => a.NewsUserAccount == nuser.NewsUserAccount && a.NewsUserPwd == nuser.NewsUserPwd).FirstOrDefault(); if (newsuser == null) { nuser.NewsUserSex = "保密"; nuser.NewsUserImage = "通用.png"; db.NewsUser.Add(nuser); db.SaveChanges(); return(RedirectToAction("LoginUser", "LoginVNKH", new { acc = nuser.NewsUserID })); } else { TempData["cunzai"] = "该账号和密码已经存在"; return(RedirectToAction("LoginUser", "LoginVNKH")); } }