Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }