public ActionResult Index(StudentDetialData stuDetialData, StudentData stuData) { bool access = true; try { if (!ModelState.IsValid) { return(View()); } stuDetialData.StudentDatas = stuData; dal.AddEntity(stuDetialData); } catch (Exception e) { ErrorDatabase error = new ErrorDatabase() { DateTime = DateTime.Now, ErrorMessage = e.Message }; errorDal.AddEntity(error); access = false; } StringBuilder builder = new StringBuilder(); if (access == true) { builder.Append("<script>alert('保存成功 准备跳转');"); builder.Append("window.location= '../../Home/Index';</script>"); return(Content(builder.ToString())); } ModelState.AddModelError("validate", "请检查您的身份证是否错误或以添加"); return(View()); }
public void TestMethod1() { bool access = true; try { StudentDb stu = new StudentDb(); StudentData studata = new StudentData { IdCard = "342626200001180191", Address = "安徽马鞍山", Telephone = "17855527769", PareventTelephone = "18855579263" }; StudentDetialData stuDetial = new StudentDetialData { Name = "李俊", Department = "计算机系", Class = "18网络2班", StudentDatas = studata }; studata.StudentDetialDatas = stuDetial; stu.studentDetialDatas.Remove(stuDetial); stu.SaveChanges(); } catch { access = false; Console.WriteLine("出现错误"); } Assert.AreEqual(access, true); }
public void TestMethod1() { StudentDataDal dal = new StudentDataDal("EFDAL"); StudentData studata = new StudentData { IdCard = "342626200001180199", Address = "安徽马鞍山", Telephone = "18855579263", PareventTelephone = "18315508706" }; StudentDetialData stuDetial = new StudentDetialData { Name = "黄伟", Department = "计算机系", Class = "18网络2班", StudentDatas = studata }; studata.StudentDetialDatas = stuDetial; var or = 0; try { or = dal.AddEntity(studata); } catch (Exception e) { Console.WriteLine(e); } bool ors = true; if (or > 0) { ors = true; } else { ors = false; } Assert.AreEqual(ors, true); }