public async Task <ActionResult> Create([Bind(Include = "StudentId,CardNumber,StudentName,Sex,NationId,Birthday,CNumber,NativePlace,TelNumber,SchoolName,Adress,ZipCode,Patriarch,Pat_Telnum,Mandator,UnifiedScore,TotalPoints,SpecialtyId,Period_CategoryId,StudentAccId")] Student student) { if (Session["Acc"] != null) { string myacc = Session["Acc"].ToString(); if (ModelState.IsValid) { student.Period_CategoryId = 1; StudentAcc sacc = await db.StudentAccs.Where(s => s.StuAcc == myacc).FirstOrDefaultAsync(); student.StudentAccId = sacc.StudentAccId; student.Time = DateTime.Now; db.Students.Add(student); await db.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } ViewBag.NationId = new SelectList(db.Nations, "NationId", "NationName", student.NationId); ViewBag.SpecialtyId = new SelectList(db.Specialtys.Where(s => s.Period_CategoryId == 1), "SpecialtyId", "SpecialtyName", student.SpecialtyId); } else { return(RedirectToAction("Index", "Home")); } return(View(student)); }
public async Task <ActionResult> DeleteConfirmed(int id) { StudentAcc studentAcc = await db.StudentAccs.FindAsync(id); db.StudentAccs.Remove(studentAcc); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "StudentAccId,StuAcc,Password")] StudentAcc studentAcc) { if (ModelState.IsValid) { db.Entry(studentAcc).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(studentAcc)); }
public async Task <ActionResult> Create([Bind(Include = "StudentAccId,StuAcc,Password")] StudentAcc studentAcc) { if (ModelState.IsValid) { db.StudentAccs.Add(studentAcc); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(studentAcc)); }
public ActionResult Student_Reg([Bind(Include = "Acc,Password,Checkpwd,Codeimg")] Register regmodel) { if (regmodel.Codeimg != Session["ValidateCode"].ToString()) { ModelState.AddModelError("", "验证码不正确"); return(View(regmodel)); } if (ModelState.IsValid) { string pwd = Tools.MD5Encrypt32(regmodel.Password); string acc = regmodel.Acc; try { var sacc = db.StudentAccs.Where(s => s.StuAcc == acc).FirstOrDefault(); if (sacc == null) { StudentAcc stuacc = new StudentAcc { StuAcc = acc, Password = pwd, Time = DateTime.Now }; try { db.Configuration.ValidateOnSaveEnabled = false; db.Configuration.AutoDetectChangesEnabled = false; db.StudentAccs.Add(stuacc); db.SaveChanges(); Session["Acc"] = stuacc.StuAcc; Session["Student"] = true; return(RedirectToAction("Index", "Home")); } catch (Exception e) { Response.Write(e.Message); } finally { db.Configuration.ValidateOnSaveEnabled = true; db.Configuration.AutoDetectChangesEnabled = true; } } else { Response.Write("<script>alert('用户名已经存在!');</script>"); } } catch (Exception ex) { Response.Write(ex.Message); } } return(View()); }
// GET: StudentAccs/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentAcc studentAcc = await db.StudentAccs.FindAsync(id); if (studentAcc == null) { return(HttpNotFound()); } return(View(studentAcc)); }
partial void DeleteStudentAcc(StudentAcc instance);
partial void UpdateStudentAcc(StudentAcc instance);
partial void InsertStudentAcc(StudentAcc instance);
public ActionResult Login([Bind(Include = "StudentAccId,StuAcc,Password")] StudentAcc studentAcc) { return(View()); }