Exemple #1
0
        public JsonResult DeleteImageWithPath(int idImage, string poth)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("deleteImage.Media.Entrée(idImage: {0})", idImage));

            string pathImage = null;
            var    imagePath = poth;


            var image = DALMedia.FindImageById(idImage);

            try
            {
                if (image.idelement != null)
                {
                    if (DALMedia.SelectAllFromElement((int)image.idelement).Count == 1)
                    {
                        pathImage = imagePath + image.nom + "." + image.format;
                        DALMedia.DeleteImage(image.Id);
                        if (System.IO.File.Exists(pathImage))
                        {
                            System.IO.File.Delete(pathImage);
                        }
                    }
                    else
                    {
                        pathImage = imagePath + image.nom + "." + image.format;
                        DALMedia.DeleteImage(image.Id);
                        if (System.IO.File.Exists(pathImage))
                        {
                            System.IO.File.Delete(pathImage);
                        }

                        //var images = MediaManager.ListeApresImage(imageBis);
                        var images = DALMedia.ListeApresImage(image);
                        DALMedia.ReorderAfterDelete(images, (int)image.ordre);
                    }
                }
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("deleteImage.Media.Exeption(exception : {0})", e));
                return(Json(ErrorList.deleteImage));
            }


            try
            {
                if (image.idchoix != null)
                {
                    var choix = DALChoix.FindById((int)image.idchoix);
                    choix.imagePath = null;
                    choix.image_id  = null;
                    DALChoix.UpdateChoix(choix);
                    pathImage = imagePath + image.nom + "." + image.format;
                    DALMedia.DeleteImage(image.Id);
                    if (System.IO.File.Exists(pathImage))
                    {
                        System.IO.File.Delete(pathImage);
                    }
                }
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("deleteImageChoix.Media.Exeption(exception : {0})", e));
                return(Json(ErrorList.deleteImageChoix));
            }

            return(Json(false));
        }