public ActionResult Create(Photo_CheckPoint photo_CheckPoint)
        {
            PhotoUtil utilPhoto          = new PhotoUtil();
            HttpFileCollectionBase image = Request.Files;

            if (image[0].FileName != "")
            {
                photo_CheckPoint.Photo_Code      = utilPhoto.EncodeImage(image[0]);
                photo_CheckPoint.Photo_Extension = Path.GetExtension(image[0].FileName);
                if (ModelState.IsValid)
                {
                    _context.Photo_CheckPoints.Add(photo_CheckPoint);
                    _context.SaveChanges();
                    return(RedirectToAction("List", "Photo_CheckPoint", new { checkPointID = photo_CheckPoint.CheckPointId }));
                }
            }
            var checkPoint = _context.Beacons.SingleOrDefault(m => m.ID == photo_CheckPoint.CheckPointId);
            PhotoCheckPointViewModel data = new PhotoCheckPointViewModel()
            {
                Photo_CheckPoint = photo_CheckPoint,
                CheckPoint       = checkPoint
            };

            return(View("New", data));
        }
Beispiel #2
0
        public void SavePhotoCheckPoint(HttpFileCollectionBase images, int checkPointId)
        {
            PhotoUtil utilPhoto = new PhotoUtil();
            List <Photo_CheckPoint> listCheckPoint = new List <Photo_CheckPoint>();

            for (int i = 0; i < images.Count; i++)
            {
                string           imageEncoded     = utilPhoto.EncodeImage(images[i]);
                Photo_CheckPoint photo_CheckPoint = new Photo_CheckPoint()
                {
                    CheckPointId    = checkPointId,
                    Photo_Code      = imageEncoded,
                    Photo_Extension = Path.GetExtension(images[i].FileName),
                    Photo_Path      = Path.GetFileNameWithoutExtension(images[i].FileName)
                };
                listCheckPoint.Add(photo_CheckPoint);
            }
            _context.Photo_CheckPoints.AddRange(listCheckPoint);
            _context.SaveChanges();
        }
        public ActionResult Update(Photo_CheckPoint photo_CheckPoint)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", photo_CheckPoint));
            }
            else
            {
                PhotoUtil utilPhoto = new PhotoUtil();

                HttpFileCollectionBase image = Request.Files;
                if (image.Count > 0 && image[0].ContentLength > 0)
                {
                    photo_CheckPoint.Photo_Code      = utilPhoto.EncodeImage(image[0]);
                    photo_CheckPoint.Photo_Extension = Path.GetExtension(image[0].FileName);
                }
                _context.Entry(photo_CheckPoint).State = EntityState.Modified;
                _context.SaveChanges();
            }
            return(RedirectToAction("List", new RouteValueDictionary(
                                        new { controller = "Photo_CheckPoint", action = "List", checkPointId = photo_CheckPoint.CheckPointId })));
        }