public ActionResult Index(string id, HttpPostedFileBase photo) { member member = db.member.Find(id); string fileName = ""; if (photo != null) { if (photo.ContentLength > 0) { string t = photo.FileName; fileName = member.member_profile.member_id + "_" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + Path.GetExtension(t); if (member.member_profile.profile_photo != null) { System.IO.File.Delete(Server.MapPath("~/images/member/" + member.member_profile.profile_photo)); } photo.SaveAs(Server.MapPath("~/images/member/" + fileName)); member.member_profile.profile_photo = fileName; } } if (ModelState.IsValid) { db.Entry(member.member_profile).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "web_Member_Index", new { id = member.member_id })); } return(View(member)); }
public ActionResult Edit(int id, string admin_email) { var admin = db.admin.Find(id); if (ModelState.IsValid) { admin.admin_email = admin_email; admin.emailConfirmed = false; var callbackUrl = Url.Action("Confirm", "Admin", new { account = admin.admin_account }, protocol: Request.Url.Scheme); GmailSender gs = new GmailSender(); gs.account = "*****@*****.**"; gs.password = "******"; gs.sender = "旅途貓 <*****@*****.**>"; gs.receiver = $"{admin.admin_email}"; gs.subject = "旅途貓驗證"; gs.messageBody = "恭喜註冊成功<br><a href=" + callbackUrl + ">請點此連結</a>"; gs.IsHtml = true; gs.Send(); db.Entry(admin).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(admin)); }
public ActionResult Edit(string id, HotelPhotoViewModel hotelPhotoViewModel, HttpPostedFileBase tourism_photo, String oldImg) { db.Entry(hotelPhotoViewModel.hotel).State = EntityState.Modified; db.SaveChanges(); string fileName = ""; if (tourism_photo != null) { if (tourism_photo.ContentLength > 0) { System.IO.File.Delete(Server.MapPath("~/images/hotel/" + oldImg)); fileName = System.IO.Path.GetFileName(tourism_photo.FileName); //取得檔案的檔名(主檔名+副檔名) tourism_photo.SaveAs(Server.MapPath("~/images/hotel/" + fileName)); //將檔案存到該資料夾 } } else { fileName = oldImg; } var tp1 = db.tourism_photo.Where(m => m.tourism_id == id).FirstOrDefault(); tp1.tourism_photo1 = fileName; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "member_id,member_account,member_password,member_status")] member member) { string email = db.member_profile.Where(m => m.member_id == member.member_id).FirstOrDefault().email; if (member.member_status == true) { GmailSender gs = new GmailSender(); gs.account = "*****@*****.**"; gs.password = "******"; gs.sender = "旅途貓 <*****@*****.**>"; gs.receiver = $"{email}"; gs.subject = "會員通知"; gs.messageBody = "<h3>親愛的會員您好:</h3><br /><p>因您已違反本網站規定,本站將取消您的會員,如有任何疑問請與本站客服人員聯絡。</p>"; gs.IsHtml = true; gs.Send(); } if (ModelState.IsValid) { db.Entry(member).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(member)); }
public IHttpActionResult Putcomment_emoji_details(long id, comment_emoji_details comment_emoji_details) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != comment_emoji_details.id) { return(BadRequest()); } db.Entry(comment_emoji_details).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!comment_emoji_detailsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit(comment comment, HttpPostedFileBase comment_photo, string oldImg) { string id = comment.tourism_id.Substring(0, 1); string controller; switch (id) { case "A": controller = "web_activities"; break; case "H": controller = "WebHotels"; break; case "R": controller = "WebRestaurants"; break; case "S": controller = "WebSpots"; break; default: controller = "web_activities"; break; } db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); //處理圖檔上傳 string fileName = ""; string rename_filename = ""; if (comment_photo != null) { if (comment_photo.ContentLength > 0) { System.IO.File.Delete(Server.MapPath("~/images/comment/" + oldImg)); fileName = System.IO.Path.GetFileName(comment_photo.FileName); //取得檔案的檔名(主檔名+副檔名) rename_filename = comment.comment_id + "_" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + Path.GetExtension(fileName); comment_photo.SaveAs(Server.MapPath("~/images/comment/" + rename_filename)); //將檔案存到該資料夾 comment.comment_photo = rename_filename; } } else { comment.comment_photo = oldImg; } //end if (ModelState.IsValid) { db.SaveChanges(); return(RedirectToRoute(new { controller = controller, action = "Details", id = comment.tourism_id })); } return(View(comment)); }
public IHttpActionResult Putmessage(long id, message message) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != message.msg_id) { return(BadRequest()); } db.Entry(message).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!messageExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit(int id, badge badge, HttpPostedFileBase badge_photo, String oldImg) { db.Entry(badge).State = EntityState.Modified; string fileName = ""; if (badge_photo != null) { if (badge_photo.ContentLength > 0) { System.IO.File.Delete(Server.MapPath("~/images/badges/" + oldImg)); fileName = System.IO.Path.GetFileName(badge_photo.FileName); //取得檔案的檔名(主檔名+副檔名) badge_photo.SaveAs(Server.MapPath("~/images/badges/" + fileName)); //將檔案存到該資料夾 } } else { fileName = oldImg; } var tp1 = db.badge.Where(m => m.badge_id == id).FirstOrDefault(); tp1.badge_photo = fileName; tp1.badge_title = badge.badge_title; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id,member_id,admin_id,issue_id,report_date,issue_content,issue_result,issue_status,resolve_date,problem_id")] issue issue) { string email = db.member_profile.Where(m => m.member_id == issue.member_id).FirstOrDefault().email; string result = issue.issue_result; string content = issue.issue_content; int id = issue.issue_id; string controller; switch (id) { case 1: controller = "issues"; break; case 2: controller = "members"; break; case 3: controller = "comments"; break; case 4: controller = "messages"; break; default: controller = "issues"; break; } if (issue.issue_status == true) { GmailSender gs = new GmailSender(); gs.account = "*****@*****.**"; gs.password = "******"; gs.sender = "旅途貓 <*****@*****.**>"; gs.receiver = $"{email}"; gs.subject = "系統問題回覆"; gs.messageBody = "<div><h3>關於您的問題:</h3><p>" + content + "</p><br></div>" + "<div><h3>以下是本網站針對此問題做出的回覆:</h3><p>" + result + "</p></div><br><footer>感謝您寶貴的建議,全體人員在此感謝。</footer>"; gs.IsHtml = true; gs.Send(); } issue.resolve_date = DateTime.Now; if (ModelState.IsValid) { db.Entry(issue).State = EntityState.Modified; db.SaveChanges(); return(RedirectToRoute(new { controller = controller, action = "Index", tab = 2 })); } ViewBag.admin_id = new SelectList(db.admin, "admin_id", "admin_account", issue.admin_id); return(View(issue)); }
public ActionResult Edit(comment comment) { if (ModelState.IsValid) { db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(comment)); }
public ActionResult Edit(string id, SpotPhotoViewModel spotPhotoViewModel, HttpPostedFileBase[] tourism_photo, String oldImg) { spotPhotoViewModel.spot.update_date = DateTime.Now; db.Entry(spotPhotoViewModel.spot).State = EntityState.Modified; db.SaveChanges(); //圖片 string fileName = ""; var tp1 = db.tourism_photo.Where(m => m.tourism_id == id).ToList(); for (int i = 0; i < 3; i++) { if (tourism_photo[i] != null) { //如果有新增檔案到input if (tourism_photo[i].ContentLength > 0) { //改名 string t = tourism_photo[i].FileName; fileName = spotPhotoViewModel.spot.spot_id + "_" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + (i + 1).ToString() + Path.GetExtension(t); if (i < tp1.Count) //如果原有紀錄 { //刪掉原檔案 System.IO.File.Delete(Server.MapPath("~/images/spot/" + tp1[i].tourism_photo1)); tourism_photo[i].SaveAs(Server.MapPath("~/images/spot/" + fileName)); //將檔案存到該資料夾 //改掉資料庫檔案 tp1[i].tourism_photo1 = fileName; } else //如果原本沒有 { tourism_photo tp = new tourism_photo(); tp.tourism_photo1 = fileName; tourism_photo[i].SaveAs(Server.MapPath("~/images/spot/" + fileName)); tp.tourism_id = spotPhotoViewModel.spot.spot_id; db.tourism_photo.Add(tp); } } //else //{ //} } //else //if(String.IsNullOrEmpty(oldImg)) //{ // tourism_photo tp = new tourism_photo(); // tp.tourism_photo1 = fileName; // tp.tourism_id = spotPhotoViewModel.spot.spot_id; // db.tourism_photo.Add(tp); //} } db.SaveChanges(); return(RedirectToAction("Index", new { page = Session["pg"] })); }
public ActionResult Edit([Bind(Include = "msg_id,msg_time,msg_content,comment_id,member_id,msg_status,tourism_id")] message message) { if (ModelState.IsValid) { db.Entry(message).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.comment_id = new SelectList(db.comment, "comment_id", "tourism_id", message.comment_id); ViewBag.member_id = new SelectList(db.member, "member_id", "member_account", message.member_id); return(View(message)); }
public ActionResult ResetPwd(string id, string newpassword) { member member = db.member.Find(id); byte[] password = System.Text.Encoding.UTF8.GetBytes(newpassword); byte[] hash = new System.Security.Cryptography.SHA256Managed().ComputeHash(password); string hashpassword = Convert.ToBase64String(hash); member.member_password = hashpassword; if (ModelState.IsValid) { db.Entry(member).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Login", "Home")); } return(View()); }