public ActionResult AddPhoto(int id = 0) { StudentPhotoViewModel vm = new StudentPhotoViewModel(); var user = new UserProfile(); if (id != 0) { user = db.UserProfiles.Find(id); } if (user == null) { return HttpNotFound(); } vm.FullName = user.FullName; vm.UserId = user.UserId; return View(vm); }
public ActionResult AddPhoto(StudentPhotoViewModel model) { var stream = Request.InputStream; string dump; using (var reader = new StreamReader(stream)) dump = reader.ReadToEnd(); var path = Server.MapPath("~/test.jpg"); System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump)); if (!ModelState.IsValid) { return View(model); } var student = db.UserProfiles.Find(model.UserId); MemoryStream target = new MemoryStream(); model.Photo.InputStream.CopyTo(target); byte[] data = target.ToArray(); student.Photo = data; db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return View(model); }
public ActionResult Capture(StudentPhotoViewModel model) { var stream = Request.InputStream; string dump; using (var reader = new StreamReader(stream)) { dump = reader.ReadToEnd(); } var bytes = String_To_Bytes2(dump); if (model.UserId == 0) { this.Session["Photo"] = bytes; } else { var student = db.UserProfiles.Find(model.UserId); student.Photo = bytes; db.Entry(student).State = EntityState.Modified; db.SaveChanges(); } return View(model); }