public IActionResult PhotoEdit(int id)
        {
            var item = _context.Items
                       .Include(i => i.Photos)
                       .Where(i => i.Id == id).FirstOrDefault();
            var model = new PhotoEditViewModel();

            model.ItemId = id;
            List <Photo> gallery = new List <Photo>();

            if (item.Photos.Any())
            {
                foreach (var photo in item.Photos)
                {
                    if (photo.Url.Contains("cover"))
                    {
                        model.Cover = photo;
                    }
                    else
                    {
                        gallery.Add(photo);
                    }
                }
                model.Gallery = gallery;
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditPhoto(string Id)
        {
            var photo = await _photoRepo.GetPhoto(Id);

            var categories = _categoryRepo.GetCategories().Select(cat => new SelectListItem
            {
                Text  = cat.Name,
                Value = cat.Name
            }).ToList();

            if (photo == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var model = new PhotoEditViewModel
            {
                Name          = photo.Name,
                Description   = photo.Description,
                PhotoUrl      = photo.PhotoUrl,
                Category      = photo.Category,
                FacebookLink  = photo.FaceBookLink,
                InstagramLink = photo.InstagramLink,
                TwitterLink   = photo.TwitterLink,
                Categories    = categories
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        // GET: Photos/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Photo photo = db.Photos.Find(id);

            if (photo == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SpotGuid = new SelectList(db.Spots, "SpotGuid", "SpotName", photo.SpotGuid);

            PhotoEditViewModel photoEditViewModel = new PhotoEditViewModel();

            photoEditViewModel.PhotoGuid   = photo.PhotoGuid;
            photoEditViewModel.SpotGuid    = photo.SpotGuid;
            photoEditViewModel.Description = photo.Description;
            photoEditViewModel.Longitude   = photo.Longitude;
            photoEditViewModel.Latitude    = photo.Latitude;

            if (photo.File != null && photo.File.Length > 0)
            {
                photoEditViewModel.File = new MemoryPostedFile(photo.File);

                var base64 = Convert.ToBase64String(photo.File);
                var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
                ViewBag.ImgSrc = imgSrc;
            }

            return(View(photoEditViewModel));
        }
Ejemplo n.º 4
0
        public ActionResult Edit([Bind(Include = "PhotoGuid,SpotGuid,Description,Longitude,Latitude,File")] PhotoEditViewModel photoEditViewModel)
        {
            if (ModelState.IsValid)
            {
                Photo photo = db.Photos.Find(photoEditViewModel.PhotoGuid);
                photo.PhotoGuid   = photoEditViewModel.PhotoGuid;
                photo.Spot        = photoEditViewModel.Spot;
                photo.Description = photoEditViewModel.Description;
                photo.Longitude   = photoEditViewModel.Longitude;
                photo.Latitude    = photoEditViewModel.Latitude;

                photo.DateModified   = DateTime.Now;
                photo.UserModifiedID = Auxiliaries.GetUserId(User);

                ViewBag.SpotGuid = new SelectList(db.Spots, "SpotGuid", "SpotName", photoEditViewModel.SpotGuid);

                // Handle the photo
                if (photoEditViewModel.File != null && photoEditViewModel.File.ContentLength > 0)
                {
                    if (!Auxiliaries.ValidImageTypes.Contains(photoEditViewModel.File.ContentType))
                    {
                        ModelState.AddModelError("File", "Izberite sliko, ki je v enem od naštetih formatov: GIF, JPG, ali PNG.");
                        if (photo.File != null && photo.File.Length > 0)
                        {
                            photoEditViewModel.File = new MemoryPostedFile(photo.File);

                            var base64 = Convert.ToBase64String(photo.File);
                            var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
                            ViewBag.ImgSrc = imgSrc;
                        }
                        return(View(photoEditViewModel));
                    }
                    else
                    {
                        using (var reader = new BinaryReader(photoEditViewModel.File.InputStream))
                        {
                            photo.File = reader.ReadBytes(photoEditViewModel.File.ContentLength);
                            int                  thumbWidth    = 250;
                            int                  thumbHeight   = 200;
                            MemoryStream         myMemStream   = new MemoryStream(photo.File);
                            System.Drawing.Image fullsizeImage = System.Drawing.Image.FromStream(myMemStream);
                            System.Drawing.Image newImage      = fullsizeImage.GetThumbnailImage(thumbWidth, thumbHeight, null, IntPtr.Zero);
                            MemoryStream         myResult      = new MemoryStream();
                            newImage.Save(myResult, System.Drawing.Imaging.ImageFormat.Jpeg);
                            byte[] myResultByte = myResult.ToArray();
                            photo.Thumbnail = myResultByte;
                        }
                    }
                }

                db.Entry(photo).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(photoEditViewModel));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> EditPhoto(PhotoEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var photo = new Photo
                {
                    Id            = model.Id,
                    Name          = model.Name,
                    Description   = model.Description,
                    Category      = model.Category,
                    FaceBookLink  = model.FacebookLink,
                    InstagramLink = model.InstagramLink,
                    TwitterLink   = model.TwitterLink
                };
                if (model.Image == null)
                {
                    photo.PhotoUrl = model.PhotoUrl;
                }
                else
                {
                    if (!String.IsNullOrWhiteSpace(model.PhotoUrl))
                    {
                        _fileManager.RemoveImage(model.PhotoUrl);
                    }
                    photo.PhotoUrl = _fileManager.SaveImage(model.Image);
                }

                await _photoRepo.UpdatePhoto(photo);

                if (await _photoRepo.SaveChangesAsync())
                {
                    return(RedirectToAction(nameof(Index)));
                }
                _clientNotification.AddToastNotification("Could not Update Photo Item", NotificationHelper.NotificationType.error, new ToastNotificationOption
                {
                    NewestOnTop       = true,
                    CloseButton       = true,
                    PositionClass     = "toast-top-right",
                    PreventDuplicates = true
                });
                return(View(model));
            }
            _clientNotification.AddToastNotification("You Have Errors", NotificationHelper.NotificationType.error, new ToastNotificationOption
            {
                NewestOnTop       = true,
                CloseButton       = true,
                PositionClass     = "toast-top-right",
                PreventDuplicates = true
            });
            return(View(model));
        }
        public IActionResult Edit(PhotoEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Photo == null)
                {
                    var obj = _db.pics.FirstOrDefault(d => d.id == model.id);

                    if (obj == null)
                    {
                        return(RedirectToAction(nameof(ShowAll)));
                    }
                    else
                    {
                        string filePath = Path.Combine(_hostingEnvironment.WebRootPath,
                                                       "images", obj.Address);
                        System.IO.File.Delete(filePath);
                    }
                }
                else
                {
                    var obj = _db.pics.FirstOrDefault(d => d.id == model.id);
                    if (obj == null)
                    {
                        return(RedirectToAction(nameof(ShowAll)));
                    }
                    else
                    {
                        string filePath = Path.Combine(_hostingEnvironment.WebRootPath,
                                                       "images", obj.Address);
                        System.IO.File.Delete(filePath);
                    }

                    var isFormatCorrect = SD.IsImage(model.Photo);
                    if (isFormatCorrect == true)
                    {
                        string uniqueFileName = EProcessUploadedFile(model.Photo);
                        obj.Address = uniqueFileName;

                        _db.pics.Update(obj);
                        _db.SaveChanges();
                    }
                    else
                    {
                        ModelState.AddModelError("", "Wrong Format File Uploaded");
                        return(View(model));
                    }
                }
            }
            return(View());
        }
        public IActionResult PhotoAdd(PhotoEditViewModel model, int id)
        {
            var item = _context.Items
                       .Include(i => i.Photos)
                       .Where(i => i.Id == id).FirstOrDefault();
            List <Photo> photos = new List <Photo>();

            if (item.Photos.Any())
            {
                photos = item.Photos.ToList();
            }
            if (model.CoverUpdate != null)
            {
                String uploadsFolder  = Path.Combine(_webHostEnvironment.WebRootPath, "images/cover");
                var    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.CoverUpdate.FileName;
                var    filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fs = new FileStream(filePath, FileMode.Create))
                {
                    model.CoverUpdate.CopyTo(fs);
                }
                photos.Add(new Photo()
                {
                    Name = uniqueFileName, Url = "~/images/cover/" + uniqueFileName, FilePath = filePath
                });
            }
            if (model.GalleryUpdate != null && model.GalleryUpdate.Count > 0)
            {
                foreach (IFormFile photo in model.GalleryUpdate)
                {
                    string uploadsFolder  = Path.Combine(_webHostEnvironment.WebRootPath, "images/gallery");
                    var    uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                    var    filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                    using (var fs = new FileStream(filePath, FileMode.Create))
                    {
                        photo.CopyTo(fs);
                    }
                    photos.Add(new Photo()
                    {
                        Name = uniqueFileName, Url = "~/images/gallery/" + uniqueFileName, FilePath = filePath
                    });
                }
            }
            item.Photos = photos;
            var updateItem = _context.Items.Attach(item);

            updateItem.State = EntityState.Modified;
            _context.SaveChanges();
            return(RedirectToAction("PhotoEdit", new { id = id }));
        }
        public IActionResult PhotoDelete(PhotoEditViewModel model, int id)
        {
            var photo = _context.Photos
                        .Where(i => i.Id == id)
                        .FirstOrDefault();

            if (System.IO.File.Exists(photo.FilePath))
            {
                System.IO.File.Delete(photo.FilePath);
            }
            _context.Remove(photo);
            _context.SaveChanges();

            return(RedirectToAction("PhotoEdit", new { id = model.ItemId }));
        }
        public IActionResult Edit(int id)
        {
            var obj = _db.pics.FirstOrDefault(t => t.id == id);

            if (obj == null)
            {
                return(RedirectToAction(nameof(ShowAll)));
            }
            else
            {
                var vm = new PhotoEditViewModel {
                };
                return(View(vm));
            }
        }
Ejemplo n.º 10
0
        public IHttpActionResult EditPhotoInfo(int id, [FromBody] PhotoEditViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var photoInfo = new PhotoEditDTO()
            {
                Title       = model.Title,
                Description = model.Description,
                UserId      = User.Identity.GetUserId(),
                PhotoId     = id
            };

            Service.Edit(photoInfo);
            return(Ok());
        }
Ejemplo n.º 11
0
        public ActionResult PhotoEdit(PhotoEditViewModel model, int id)
        {
            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                //retrieve photo and update with new info
                PhotoEntityModel entity = cx.Photos.FirstOrDefault(p => p.Id == id);

                entity.Name = model.Name;

                entity.Description = model.Description;

                entity.DateChanged = DateTime.Now;

                cx.SaveChanges();
            }

            System.Threading.Thread.Sleep(800);//simulate waiting time

            return(RedirectToAction("Dashboard"));
        }
        public ActionResult PhotoEdit(PhotoEditViewModel model, int id)
        {
            photoRepo.UpdatePhoto(id, model.Name, model.Description);

            #region notused
            //using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            //{
            //    //retrieve photo and update with new info
            //    PhotoEntityModel entity = cx.Photos.FirstOrDefault(p => p.Id == id);

            //    entity.Name = model.Name;

            //    entity.Description = model.Description;

            //    entity.DateChanged = DateTime.Now;

            //    cx.SaveChanges();
            //}
            #endregion

            System.Threading.Thread.Sleep(800);//simulate waiting time

            return(RedirectToAction("Dashboard"));
        }