public ActionResult DeleteConfirmed(int id) { SchoolSystem.DbModels.Model.Student student = db.students.Find(id); db.students.Remove(student); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "StudentId,LastName,FirstName,EmailAddress,ConfirmEmailAddress,Password ,ConfirmPassword, PhoneNumber,DateOfBirth,Postalcode,Comment,ImageUrl,RegisteredOn,Department")] Student student) { SchoolSystem.DbModels.Model.Student studentToEdit = new SchoolSystem.DbModels.Model.Student { StudentId = student.StudentId, FirstName = student.FirstName, LastName = student.LastName, EmailAddress = student.EmailAddress, Password = student.Password, PhoneNumber = student.PhoneNumber, DateOfBirth = student.DateOfBirth, Postalcode = student.Postalcode, Comment = student.Comment, Url = student.Url, RegisteredOn = student.RegisteredOn, DepartmentId = int.Parse(student.Department) }; if (ModelState.IsValid) { db.Entry(studentToEdit).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
/* * public ActionResult Create(FormCollection frmCollection) * { * foreach (var key in frmCollection.AllKeys) * { * Response.Write( key + " " + key[]); * } */ public ActionResult Create([Bind(Include = "StudentId, LastName,FirstName,EmailAddress,ConfirmEmailAddress, Password, ConfirmPassword, PhoneNumber,DateOfBirth, PostalCode,Comment, Url,DepartmentId")] Student student) //, HttpPostedFileBase file) { if (ModelState.IsValid) { SchoolSystem.DbModels.Model.Student studentToSave = new SchoolSystem.DbModels.Model.Student() { StudentId = student.StudentId, LastName = student.LastName, FirstName = student.FirstName, EmailAddress = student.EmailAddress, Password = student.Password, PhoneNumber = student.PhoneNumber, DateOfBirth = student.DateOfBirth, Postalcode = student.Postalcode, Comment = student.Comment, Url = student.Url, DepartmentId = student.DepartmentId }; /* * * if (file != null) * { * string pic = System.IO.Path.GetFileName(file.FileName); * string path = System.IO.Path.Combine( * Server.MapPath("~/images/profile"), pic); * // file is uploaded * file.SaveAs(path); * * // save the image path path to the database or you can send image * // directly to database * // in-case if you want to store byte[] ie. for DB * using (MemoryStream ms = new MemoryStream()) * { * file.InputStream.CopyTo(ms); * byte[] array = ms.GetBuffer(); * } * * }*/ db.students.Add(studentToSave); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create([Bind(Include = "StudentId,LastName,FirstName,EmailAddress,ConfirmEmailAddress,Password,ConfirmPassword,PhoneNumber,DateOfBirth,PostalCode,Comment,Url,DepartmentId")] Student student) { if (ModelState.IsValid) { var studentToSave = new SchoolSystem.DbModels.Model.Student() { StudentId = student.StudentId, LastName = student.LastName, FirstName = student.FirstName, EmailAddress = student.EmailAddress, Password = student.Password, PhoneNumber = student.PhoneNumber, DateOfBirth = student.DateOfBirth, Postalcode = student.Postalcode, Comment = student.Comment, Url = student.Url, DepartmentId = student.DepartmentId }; db.students.Add(studentToSave); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }