public ActionResult Edit(int id, 客戶資料 form) { var customerdata = customerdatasRepo.Find(id); string oldPwd = customerdata.密碼; string encryptNewPwd = new EncodeCryptHelper().Encode(form.密碼); string NewPwd = form.密碼; // TryUpdataModel. Exclude // 利用 TryUpdateModel 來繫結我們要的資料,用這樣的方式就可以避免資料繫結的時候更新到我們不要的資訊,也可以避免一些安全性的問題。 // Q:繫結的資料是從哪邊來的? // A:預設它會從表單接收到的資料,只要名稱一樣就會自己繫結 if (TryUpdateModel(customerdata, "", new string[] { "密碼", "電話", "傳真", "地址", "Email" }, new string[] {})) { if ((oldPwd != encryptNewPwd) && (oldPwd != NewPwd)) { customerdata.密碼 = encryptNewPwd; } customerdatasRepo.UnitOfWork.Commit(); return(RedirectToAction("Index")); } SetCategoryDDLListItem(); return(View(customerdata)); }
public bool ISMember(string account, string password) { password = new EncodeCryptHelper().Encode(password); var count = this.All().Where(s => s.帳號 == account && s.密碼 == password).Count(); if (count > 0) { return(true); } return(false); }