public ActionResult Close(string id) { using (SystemDbContext mydb = new SystemDbContext()) { List<UserModels> tmp = mydb.Users.Where(p => p.CompanyId.Equals(id)).ToList(); foreach(UserModels user in tmp) user.IsProved = false; mydb.Entry(tmp).State = System.Data.Entity.EntityState.Modified; mydb.SaveChanges(); return RedirectToAction("Index"); } }
public JsonResult GenerateVerifyCode() { var PhoneNumber = Request["PhoneNumber"]; string code = (new Random().Next(1111, 9999)).ToString(); string content = "盆景办公提醒您,您的验证码为:" + code; //向用户发送验证码 // int rect = sendOnce(PhoneNumber, content); int rect = 1; //短信验证发送失败! if (rect <= 0) { return Json(new { errorcode = rect }); } using (var vCode = new SystemDbContext()) { var tmp = vCode.VerifyCodes.Find(PhoneNumber); DateTime createTime = System.DateTime.Now; //电话在数据库中已经存在,更新Code和CreateTime以及OverTime就可以 if (tmp != null) { tmp.Code = code; tmp.CreateTime = createTime; tmp.OverTime = createTime.AddSeconds(VerifyCodeOverTimeSeconds); vCode.Entry(tmp).State = System.Data.Entity.EntityState.Modified; vCode.SaveChanges(); } else { VerifyCode tmpCode = new VerifyCode(); tmpCode.Code = code; tmpCode.PhoneNumber = PhoneNumber; tmpCode.CreateTime = createTime; tmpCode.OverTime = createTime.AddSeconds(VerifyCodeOverTimeSeconds); vCode.VerifyCodes.Add(tmpCode); vCode.SaveChanges(); } } return Json(new { errorcode="1"}); }