public JsonResult DeleteChoix(int idChoix) { Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("deleteChoix.Choix.Entrée(idChoix: {0})", idChoix)); var pothImage = Path.Combine(Server.MapPath(ConfigHelper._CST_DIRECTORY_IMAGE)); MediaController med = new MediaController(); var choix = DALChoix.FindById(idChoix); try { if (choix.image_id != null) { med.DeleteImage((int)choix.image_id, pothImage); DALMedia.DeleteImage((int)choix.image_id); } DALChoix.DeleteChoix(idChoix); } catch (Exception e) { Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("deleteChoix.Choix.Exception(Exception: {0})", e)); return(Json(ErrorList.deleteChoix)); } return(Json(1)); }
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)); }