コード例 #1
0
ファイル: UserController.cs プロジェクト: applenele/NewRen
 public ActionResult PictureEdit(vEdit model, HttpPostedFileBase file)
 {
     User user = db.Users.Find(model.ID);
     if (user != null)
     {
         try
         {
             if (ModelState.IsValid)
             {
                 user.Picture = model.Picture;
                 if (file != null)
                 {
                     System.IO.Stream stream = file.InputStream;
                     //byte[] buffer = new byte[stream.Length];
                     //stream.Read(buffer, 0, (int)stream.Length);
                     //stream.Close();
                     byte[] buffer = Image.CompressionImage(stream, 10);
                     user.Picture = buffer;
                 }
                 db.SaveChanges();
                 return RedirectToAction("Show/" + model.ID);
             }
             else
             {
                 ModelState.AddModelError("", "修改的信息输入错误!");
             }
             ViewBag.user = user;
             return View(model);
         }
         catch (Exception ex)
         {
             log.Error(new LogContent("修改图像页面出错", HttpHelper.GetIPAddress()), ex);
             return Redirect("/User/PictureEdit/" + model.ID);
         }
     }
     else
     {
         return Redirect("/Shared/info?msg=该用户不存在,请不要不合理操作");
     }
 }
コード例 #2
0
ファイル: UserController.cs プロジェクト: applenele/NewRen
 public ActionResult Edit(vEdit model, int? cityID, int? districtID, int? townID)
 {
     User user = db.Users.Find(model.ID);
     if (user != null)
     {
         try
         {
             ViewBag.user = user;
             if (ModelState.IsValid)
             {
                 if (cityID.HasValue)
                 {
                     var city = db.Cities.Find(cityID);
                     user.City = city.CityName;
                 }
                 if (districtID.HasValue)
                 {
                     var district = db.Districts.Find(districtID);
                     user.District = district.DistrictName;
                 }
                 if (townID.HasValue)
                 {
                     var town = db.Towns.Find(townID);
                     user.Town = town.TownName;
                 }
                 user.SexAsInt = model.SexAsInt;
                 user.Phone = model.Phone;
                 user.Address = model.Address;
                 user.Birthday = model.Birthday;
                 user.Email = model.Email;
                 user.RealName = model.RealName;
                 user.QQ = model.QQ;
                 user.WhatApp = model.WhatApp;
                 user.Job = model.Job;
                 user.Description = model.Description;
                 user.UserGroupID = model.UserGroupID;
                 db.SaveChanges();
                 //FormsAuthentication.SetAuthCookie(model.UserName, false);
                 return RedirectToAction("Show/" + user.ID);
             }
             else
             {
                 ModelState.AddModelError("", "修改的信息输入错误!");
             }
             List<SelectListItem> ListSex = new List<SelectListItem>();
             ListSex.Add(new SelectListItem { Text = "女", Value = "0", Selected = (user.SexAsInt == 0 ? true : false) });
             ListSex.Add(new SelectListItem { Text = "男", Value = "1", Selected = (user.SexAsInt == 1 ? true : false) });
             ViewBag.Sex = ListSex;
             ViewBag.Jobs = db.Jobs.ToList();
             ViewBag.Cities = db.Cities.ToList();
             ViewBag.user = user;
             return View();
         }
         catch (Exception ex)
         {
             log.Error(new LogContent("修改个人信息出错", HttpHelper.GetIPAddress()), ex);
             return Redirect("/User/DescriptionShow/" + model.ID);
         }
     }
     else
     {
         return Redirect("/Shared/info?msg=该用户不存在,请不要不合理操作");
     }
 }
コード例 #3
0
 public ActionResult PictureEdit(vEdit model, int id, HttpPostedFileBase file)
 {
     UserGroup user = db.UserGroups.Find(model.ID);
     try
     {
         if (file != null)
         {
             System.IO.Stream stream = file.InputStream;
             byte[] buffer = new byte[stream.Length];
             stream.Read(buffer, 0, (int)stream.Length);
             stream.Close();
             model.Picture = buffer;
             user.Picture = model.Picture;
         }
         else
         {
             user.Picture = model.Picture;
         }
         db.SaveChanges();
         return RedirectToAction("Show/" + user.ID);
     }
     catch (Exception ex)
     {
         log.Error(new LogContent("修改头像出错", HttpHelper.GetIPAddress()), ex);
         return View(user);
     }
 }
コード例 #4
0
 public ActionResult UserEdit(vEdit model, int id)
 {
     User user = db.Users.Find(model.ID);
     if (user == null)
     {
         return Redirect("/Shared/Info?msg=该牛人不存在,请不要不合理操作");
     }
     else
     {
         if (ModelState.IsValid)
         {
             try
             {
                 ViewBag.user = user;
                 user.SexAsInt = model.SexAsInt;
                 user.Address = model.Address;
                 user.Birthday = model.Birthday;
                 user.Email = model.Email;
                 user.RealName = model.RealName;
                 user.QQ = model.QQ;
                 user.WhatApp = model.WhatApp;
                 user.Job = model.Job;
                 user.City = model.City;
                 user.District = model.District;
                 user.Town = model.Town;
                 user.Description = model.Description;
                 db.SaveChanges();
                 return RedirectToAction("UserShow/" + user.ID);
             }
             catch (Exception ex)
             {
                 log.Error(new LogContent("修改牛人出错", HttpHelper.GetIPAddress()), ex);
                 ModelState.AddModelError("", "保存修改信息出现错误,请重试!");
             }
         }
         else
         {
             ModelState.AddModelError("", "修改的信息输入错误!");
         }
         ViewBag.User = user;
         ViewBag.UserGroup = db.UserGroups.Find(user.UserGroupID);
         List<SelectListItem> ListSex = new List<SelectListItem>();
         ListSex.Add(new SelectListItem { Text = "女", Value = "0", Selected = (user.SexAsInt == 0 ? true : false) });
         ListSex.Add(new SelectListItem { Text = "男", Value = "1", Selected = (user.SexAsInt == 1 ? true : false) });
         ViewBag.Jobs = db.Jobs.ToList();
         ViewBag.Cities = db.Cities.ToList();
         ViewBag.Sex = ListSex;
         return View();
     }
 }
コード例 #5
0
 public ActionResult PictureEdit(vEdit model, int id, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         Business business = db.Businesses.Find(model.ID);
         try
         {
             if (file != null)
             {
                 System.IO.Stream stream = file.InputStream;
                 byte[] buffer = new byte[stream.Length];
                 stream.Read(buffer, 0, (int)stream.Length);
                 stream.Close();
                 model.Picture = buffer;
                 business.Picture = model.Picture;
             }
             else
             {
                 business.Picture = model.Picture;
             }
             db.SaveChanges();
             return RedirectToAction("Show/" + model.ID);
         }
         catch (Exception ex)
         {
             log.Error(new LogContent("修改商户图片出错", HttpHelper.GetIPAddress()), ex);
             ModelState.AddModelError("", "图片信息有误,请重新上传");
         }
     }
     else
     {
         ModelState.AddModelError("", "信息异常,请刷新页面重新上传");
     }
     ViewBag.Business = db.Businesses.Find(model.ID);
     return View();
 }