Esempio n. 1
0
        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");
        }
Esempio n. 2
0
 public ActionResult Delete(Student student)
 {
     var _student = _ctx.Students.FirstOrDefault(x => x.ID == student.ID);
     _ctx.Students.Remove(_student);
     return RedirectToAction("List", "Student");
 }
Esempio n. 3
0
 public void UpdateStudent(Student student)
 {
     _studentRepository.Update(student);
     _unitOfWork.Commit();
 }
Esempio n. 4
0
 public ActionResult Edit(Student student)
 {
     _ctx.Students.Attach(student);
     _ctx.Entry(student).State=EntityState.Modified;
     _ctx.SaveChanges();
     return RedirectToAction("List", "Student");
 }
Esempio n. 5
0
 public void CreateStudent(Student student)
 {
     _studentRepository.Add(student);
     _unitOfWork.Commit();
 }