Example #1
0
 public ActionResult Edit([Bind(Include = "ID,Name,Sex,Department,PhoneNumber,EnterDate")] Staff staff)
 {
     if (ModelState.IsValid)
     {
         //性别判断
         if (staff.Sex != "男" && staff.Sex != "女")
         {
             staff.SexJudge = "性别填写存在错误,必须是男女";
         }
         //电话号码判断
         Regex RegMobilePhone = new Regex("^1[3|5|8][0-9]{9}$");
         if (staff.PhoneNumber.Length != 11 || !RegMobilePhone.IsMatch(staff.PhoneNumber))
         {
             staff.PhoneNumberJudge = "电话号码填写存在错误";
         }
         //页面返回
         if (staff.SexJudge != null || staff.PhoneNumberJudge != null)
         {
             return(View(staff));
         }
         else
         {
             db.Entry(staff).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     return(View(staff));
 }
 public ActionResult Edit([Bind(Include = "StaffId,StaffUsername,StaffPassword")] Staff staff)
 {
     if (ModelState.IsValid)
     {
         db.Entry(staff).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(staff));
 }