public ActionResult Create(Student student) { try { if (ModelState.IsValid) { if (Request.Files.Count==1) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { using (var reader = new System.IO.BinaryReader(file.InputStream)) { student.Photo = reader.ReadBytes(file.ContentLength); } } } var studentModel = new Student() { Name = student.Name, Birthdate = student.Birthdate, Photo = student.Photo }; _ctx.Students.Add(studentModel); _ctx.SaveChanges(); } } catch (RetryLimitExceededException dex ) { //Log the error (uncomment dex variable name and add a line here to write a log. Response.Write(dex.Message); ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return RedirectToAction("List", "Student"); }
public ActionResult Delete(Student student) { var _student = _ctx.Students.FirstOrDefault(x => x.ID == student.ID); _ctx.Students.Remove(_student); return RedirectToAction("List", "Student"); }
public void UpdateStudent(Student student) { _studentRepository.Update(student); _unitOfWork.Commit(); }
public ActionResult Edit(Student student) { _ctx.Students.Attach(student); _ctx.Entry(student).State=EntityState.Modified; _ctx.SaveChanges(); return RedirectToAction("List", "Student"); }
public void CreateStudent(Student student) { _studentRepository.Add(student); _unitOfWork.Commit(); }