Esempio n. 1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var photo = db.Photos.Find(id);
            var vm    = new EditPhotoViewModel()
            {
                Id                    = photo.PhotoID,
                Date                  = photo.TimeStamp,
                Description           = photo.PhotoDesc,
                Title                 = photo.PhotoTitle,
                InLandingPageCarousel = photo.InLandingPageCarousel,
                InPartnerOrgCarousel  = photo.InPartnerOrgCarousel,
                InPhotoGallery        = photo.InPhotoGallery,
                Link                  = photo.Link,
                Credit                = photo.Credit
            };

            if (photo == null)
            {
                return(HttpNotFound());
            }

            return(View(vm));
        }
Esempio n. 2
0
        public IActionResult EditPhoto(EditPhotoViewModel epvm)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            Photo photo = _photoRepository.GetphotoByID(epvm.PhotoId);

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

            if (photo.NRAKOUserId != CurrentUser.Id &&
                !(IsAdmin))
            {
                return(RedirectToAction("Index"));
            }

            photo.DateModified = DateTime.Now;
            photo.Description  = epvm.Description;

            string[] hashtags = epvm.Hashtags.Split(' ');

            _photoRepository.RemovePhotoHashTags(photo.Id);

            _photoRepository.AddHashtagsToPhoto(hashtags, photo.Id);

            _logger.Log(CurrentUser.Id, $"Edited photo @{photo.Url}, Description: {photo.Description}, Hashtags: {epvm.Hashtags}");

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(string id, EditPhotoViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                var licenses = this.licenseService.GetAll();
                model.Licenses = licenses;

                return(this.View(model));
            }

            try
            {
                var user = await this.userManager.GetUserAsync(this.User);

                await this.photoService.UpdatePhotoAsync(id, user.Id, model);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                var licenses = this.licenseService.GetAll();
                model.Licenses = licenses;
                return(this.View(model));
            }

            return(this.RedirectToAction("Show", "Photo", new { Id = id }));
        }
Esempio n. 4
0
        public static EditPhotoViewModel GetEditPhotoViewModelFromPhoto(Photo photo)
        {
            EditPhotoViewModel epvm = new EditPhotoViewModel();

            epvm.Description = photo.Description;
            epvm.Hashtags    = String.Join(' ', photo.PhotosHashtags.Select(ph => new string(ph.Hashtag.Text)).ToList());
            epvm.PhotoId     = photo.Id;
            epvm.Url         = photo.Url;

            return(epvm);
        }
        public ActionResult EditPhoto(EditPhotoViewModel model)
        {
            List <ProductPhoto> Photos = new List <ProductPhoto>();

            if (ModelState.IsValid)
            {
                AppDbContext dbContext = new AppDbContext();

                List <ProductPhoto> exPhotos = model.Photos;

                if (exPhotos != null)
                {
                    foreach (var exPhoto in exPhotos)
                    {
                        System.IO.File.Delete(exPhoto.Src);
                        dbContext.deleteProductPhoto(exPhoto.Id);
                    }
                }
                foreach (var photo in model.Photo)
                {
                    var fileName   = Path.GetFileName(photo.FileName);
                    var path       = "/Public/Products/" + model.Model;
                    var photoUrl   = Server.MapPath(path);
                    var photoTitle = Path.GetFileNameWithoutExtension(photo.FileName);
                    var uniqName   = Guid.NewGuid().ToString() + "_" + fileName;

                    if (!Directory.Exists(photoUrl))
                    {
                        Directory.CreateDirectory(photoUrl);
                    }

                    var          photoPath = Path.Combine(photoUrl, uniqName);
                    ProductPhoto newPhoto  = new ProductPhoto
                    {
                        Path  = path,
                        Src   = photoPath,
                        Title = uniqName,
                    };
                    Photos.Add(newPhoto);

                    photo.SaveAs(photoPath);
                }

                dbContext.addProductPhoto(Photos);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 6
0
        public ActionResult Edit(int?id)
        {
            PhotoDTO photoDto;

            try
            {
                photoDto = photoService.GetById(id);
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PhotoDTO, EditPhotoViewModel>()).CreateMapper();
            EditPhotoViewModel photoView = mapper.Map <PhotoDTO, EditPhotoViewModel>(photoDto);

            return(View(photoView));
        }
Esempio n. 7
0
        public async Task UpdatePhotoAsync(string photoId, string userId, EditPhotoViewModel model)
        {
            var photo = this.photoRespository.All().Where(x => x.Id == photoId && x.OwnerId == userId).FirstOrDefault();

            if (photo == null)
            {
                throw new Exception("Such photo does not exists!");
            }

            photo.Title            = model.Title;
            photo.Description      = model.Description;
            photo.LicenseId        = model.LicenseId;
            photo.IsCommentAllowed = model.IsCommentAllowed;
            photo.IsPrivate        = model.IsPrivate;

            await this.photoRespository.SaveChangesAsync();
        }
        public ActionResult EditPhoto(int id)
        {
            AppDbContext        dbContext = new AppDbContext();
            List <ProductPhoto> photos    = new List <ProductPhoto>();

            photos = dbContext.getProductPhotos(id).ToList();
            ProductModels product = dbContext.getProducts.SingleOrDefault(p => p.Id == id);
            ModelModels   model   = dbContext.getModels.SingleOrDefault(m => m.Id == product.ModelId);

            EditPhotoViewModel editPhoto = new EditPhotoViewModel
            {
                Model     = model.Name,
                ProductId = id,
                Photos    = photos
            };

            return(View(editPhoto));
        }
Esempio n. 9
0
        public ActionResult Edit(EditPhotoViewModel photoVM, FormCollection collection, HttpPostedFileBase image = null)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var photoToUpdate = db.Photos.FirstOrDefault(x => x.PhotoID == photoVM.Id);
                    if (photoToUpdate != null)
                    {
                        photoToUpdate.PhotoDesc             = photoVM.Description;
                        photoToUpdate.InLandingPageCarousel = photoVM.InLandingPageCarousel;
                        photoToUpdate.InPartnerOrgCarousel  = photoVM.InPartnerOrgCarousel;
                        photoToUpdate.InPhotoGallery        = photoVM.InPhotoGallery;
                        photoToUpdate.PhotoTitle            = photoVM.Title;
                        photoToUpdate.Link   = photoVM.Link;
                        photoToUpdate.Credit = photoVM.Credit;
                    }

                    if (image != null)
                    {
                        byte[] uploadedImage = new byte[image.InputStream.Length];
                        image.InputStream.Read(uploadedImage, 0, image.ContentLength);
                        photoToUpdate.PhotoData = uploadedImage;
                        photoToUpdate.MimeType  = image.ContentType;

                        var imageToResize = Image.FromStream(image.InputStream);

                        photoToUpdate.ThumbnailPhotoContent = GetImageThumbnail(imageToResize);
                    }

                    db.Entry(photoToUpdate).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    TempData["message"] = string.Format($"{photoVM.Title} photo has been updated!");
                    return(RedirectToAction("Admin"));
                }

                return(RedirectToAction("Admin"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 10
0
        public IActionResult EditPhoto(int id)
        {
            Photo photo = _photoRepository.GetphotoByID(id);

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

            if (photo.NRAKOUserId != CurrentUser.Id &&
                !(IsAdmin))
            {
                return(RedirectToAction("Index"));
            }


            EditPhotoViewModel epvm = Helpers.Helpers.GetEditPhotoViewModelFromPhoto(photo);

            return(View(epvm));
        }
Esempio n. 11
0
        public async Task <IActionResult> Edit(int id, EditPhotoViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var photo = await this.photos.FindForEdit(id);

            if (photo == null)
            {
                return(this.BadRequest());
            }

            if (user.Id != photo.AdUserId &&
                user.Id != photo.AlbumUserId &&
                !this.User.IsInRole(WebConstants.AdministratorRole))
            {
                return(this.BadRequest());
            }

            var success = await this.photos.Edit(
                id,
                model.Description,
                model.Location,
                model.Latitude,
                model.Longitude,
                model.Tags);

            if (!success)
            {
                return(this.BadRequest());
            }

            this.TempData.AddSuccessMessage($"The photo details have been successfully changed.");
            return(this.RedirectToAction("Details", "Photos", new { area = "", id = id }));
        }
Esempio n. 12
0
        public ActionResult Edit(EditPhotoViewModel photoView)
        {
            if (ModelState.IsValid)
            {
                var      mapper   = new MapperConfiguration(cfg => cfg.CreateMap <EditPhotoViewModel, PhotoDTO>()).CreateMapper();
                PhotoDTO photoDto = mapper.Map <EditPhotoViewModel, PhotoDTO>(photoView);
                try
                {
                    photoService.Edit(photoDto);
                }
                catch (ValidationException)
                {
                    return(HttpNotFound());
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(photoView));
            }
        }
Esempio n. 13
0
        public async Task <IActionResult> Edit(Guid id, EditPhotoViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var updateDTO = new UpdatePhotoDTO()
                    {
                        Title       = model.Title,
                        Description = model.Description
                    };
                    var photo = await this.photoService.UpdateAsync(updateDTO, id);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception e)
                {
                    toastNotification.AddErrorToastMessage(e.Message, new NotyOptions());
                    var path = Request.Path.Value.ToString() + model.Id;
                    return(Redirect(path));
                }
            }
            return(View(model));
        }
Esempio n. 14
0
        public async Task <object> EditPhoto(EditPhotoViewModel editPhoto)
        {
            await fileService.EditPhoto(editPhoto.ApplicationUser, editPhoto.Photo);

            return(Ok("Changed"));
        }