Beispiel #1
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Email,DOB,Password,RePassword")] Students students)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(students);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(students));
        }
 public static void Initialize(StudDbContext context)
 {
     if (!context.Students.Any())
     {
         context.Students.AddRange(
             new Student
         {
             FirstName  = "iPhone X",
             LastNAme   = "Apple",
             MiddleName = "leon",
             Sex        = "муж",
             CallName   = "dfgdfg"
         },
             new Student
         {
             FirstName  = "iPhone X",
             LastNAme   = "Apple",
             MiddleName = "leon",
             Sex        = "жен",
             CallName   = "dfgdfg"
         }
             );
         context.SaveChanges();
     }
 }
Beispiel #3
0
 public IActionResult AddStudent(Student student)
 {
     try
     {
         db.Students.Add(student);
         db.SaveChanges();
         return(Redirect("~/Home/Index"));
     }
     catch
     {
         return(View());
     }
 }