Esempio n. 1
0
 public ActionResult Edit(int id, EditImagesViewModel model)
 {
     try
     {
         string FileName = UploadFile(model.File, model.ImageUrl);
         if (ModelState.IsValid)
         {
             var Projects = projectRepository.Find(model.ProjectId);
             if (Projects == null)
             {
                 ModelState.AddModelError("", "please review the input fileds");
                 return(View(GetAllProjects()));
             }
             var photo = new Photos
             {
                 Image   = FileName,
                 Project = Projects
             };
             imageRepository.Update(model.Id, photo);
             return(RedirectToAction("index"));
         }
         return(View(model));
     }
     catch
     {
         return(View(model));
     }
 }
Esempio n. 2
0
        public ActionResult EditImages([FromForm] EditImagesViewModel model, int prodid)
        {
            try
            {
                var images = _mainRepository.GetImagesByProductID(prodid).ToList();

                var firstImage = _mainRepository.GetImageByOrderIndex(prodid, 0);
                if (model.FirstImageFile != null)
                {
                    firstImage.Link = GetImageFilePath(model.FirstImageFile);
                }
                else
                {
                    firstImage.Link = model.FirstImageLink ?? DefaultImageLink;
                }
                firstImage.Description = model.FirstImageDescription;

                var secondImage = _mainRepository.GetImageByOrderIndex(prodid, 1);
                if (model.SecondImageFile != null)
                {
                    secondImage.Link = GetImageFilePath(model.SecondImageFile);
                }
                else
                {
                    secondImage.Link = model.SecondImageLink ?? DefaultImageLink;
                }
                secondImage.Description = model.SecondImageDescription;

                var thirdImage = _mainRepository.GetImageByOrderIndex(prodid, 2);
                if (model.ThirdImageFile != null)
                {
                    thirdImage.Link = GetImageFilePath(model.ThirdImageFile);
                }
                else
                {
                    thirdImage.Link = model.ThirdImageLink ?? DefaultImageLink;
                }
                thirdImage.Description = model.ThirdImageDescription;

                _mainRepository.UpdateImage(firstImage);
                _mainRepository.UpdateImage(secondImage);
                _mainRepository.UpdateImage(thirdImage);
                return(RedirectToAction("Page"));
            }
            catch
            {
                return(RedirectToAction("Page"));
            }
        }
        public async Task <IActionResult> EditImages(Guid etablissementId)
        {
            try
            {
                EditImagesViewModel model = new EditImagesViewModel(NOMBREMAXPHOTOS, TAILLEMAXIMAGE, etablissementId, TAILLEMAXLOGO);

                //récupère le path vers le logo si il existe
                Etablissement etabl = await etablissementService.GetEtablissementAsync(etablissementId);

                if (etabl.Logo != null)
                {
                    model.PathLogo = Path.Combine("\\", "img", "Etablissement", etabl.Id.ToString(), "Logo", etabl.Logo);
                }

                //récupère les path vers les images
                List <PhotoEtablissement> lPhotos = await photoService.GetAllPhotosAsync();

                lPhotos = lPhotos.Where(x => x.EtablissementId == etablissementId).ToList();
                List <PhotoGeneriqueViewModel> lPathImages = new List <PhotoGeneriqueViewModel>();
                if (lPhotos != null)
                {
                    foreach (PhotoEtablissement photo in lPhotos)
                    {
                        PhotoGeneriqueViewModel photoGenerique = new PhotoGeneriqueViewModel();
                        photoGenerique.Path = Path.Combine("\\", "img", "Etablissement", etabl.Id.ToString(), "Photos", photo.NomFichier);
                        photoGenerique.id   = photo.Id;
                        lPathImages.Add(photoGenerique);
                    }
                }
                model.lPathImages = lPathImages;

                return(View(model));
            }
            catch (Exception ex)
            {
                ErrorViewModel vme = new ErrorViewModel()
                {
                    RequestId = ex.Message
                };
                return(View("Error", vme));
            }
        }
Esempio n. 4
0
        public ActionResult Edit(int id)
        {
            var image = imageRepository.Find(id);

            if (image == null)
            {
                return(NotFound());
            }

            var projectid = image.Project == null ? image.Project.ID = 0 : image.Project.ID;
            var model     = new EditImagesViewModel
            {
                Id        = image.ID,
                ImageUrl  = image.Image,
                ProjectId = projectid,
                Projects  = FillProjects()
            };

            return(View(model));
        }
        public async Task <IActionResult> EditImages(EditImagesViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var idToken = await HttpContext.GetTokenAsync("access_token");

                    //met à jour l'établissement avec le nouveau logo le cas échéant
                    if (model.PathLogo == null && model.Logo != null)
                    {
                        Etablissement etab = await etablissementService.GetEtablissementAsync(model.EtablissementId);

                        if (etab.Logo != null)
                        {
                            string PathLogo = Path.Combine(hostingEnvironment.WebRootPath, "img", "Etablissement", etab.Id.ToString(), "Logo", etab.Logo);
                            deleteImage(PathLogo);
                        }

                        etab.Logo = createLogo(etab.Id, model.Logo);
                        var result = await etablissementService.UpdateEtablissementAsync(etab, idToken);
                    }

                    //supprime les photos le cas échéant
                    if (model.lPathImages != null)
                    {
                        List <PhotoGeneriqueViewModel> lPhotosASupprimer = new List <PhotoGeneriqueViewModel>();
                        lPhotosASupprimer = model.lPathImages.Where(x => x.IsToBeDeleted).ToList();
                        if (lPhotosASupprimer != null)
                        {
                            foreach (PhotoGeneriqueViewModel photo in lPhotosASupprimer)
                            {
                                string PathLogo = Path.Join(hostingEnvironment.WebRootPath, photo.Path);
                                deleteImage(PathLogo);
                                var result = photoService.DeletePhotoAsync(photo.id, idToken);
                            }
                        }
                    }

                    //rajoute les photos le cas échéant
                    List <PhotoGeneriqueViewModel> lPhotosARajouter = new List <PhotoGeneriqueViewModel>();
                    lPhotosARajouter = model.Photos.Where(x => x.Photo != null).ToList();
                    if (lPhotosARajouter != null)
                    {
                        foreach (PhotoGeneriqueViewModel photo in lPhotosARajouter)
                        {
                            createPhoto(model.EtablissementId, photo);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorViewModel vme = new ErrorViewModel()
                    {
                        RequestId = ex.Message
                    };
                    return(View("Error", vme));
                }
            }
            return(RedirectToAction("ListeEtablissementOwned"));
        }