public ActionResult ApresDescription(int idElement)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("apresDescription.UserQuestionnaire.Entrée(idElement : {0})", idElement));

            ViewModelUserQuestionnaire model = new ViewModelUserQuestionnaire();

            try
            {
                var      element          = DALElement.FindById(idElement);
                Elements descriptionApres = DALElement.SelectElementApresDescription(element);
                Elements elementApres     = DALElement.elementOrdreApres(element);
                if (elementApres.Id == DALSession.element.Id || descriptionApres.Id == DALSession.element.Id)
                {
                    return(RedirectToAction("RetourElementEnCours", "UserQuestionnaire"));
                }
                else
                {
                    model.element    = descriptionApres;
                    model.imagesUp   = DALMedia.SelectAllFromElement(descriptionApres.Id);
                    model.imagesDown = DALMedia.SelectAllFromElementDown(descriptionApres.Id);
                }
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("apresDescription.UserQuestionnaire.Sortie(idElement description Apres: {0})", descriptionApres.Id));
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("apresDescription.UserQuestionnaire.Excpetion(Exception : {0})", e));
                ViewBag.Error = ErrorList.apresDescription;
            }


            return(View(model));
        }
Beispiel #2
0
        public ActionResult PageUpdateDescription(ViewModelQuestionnaireElements model) /* idQuestionnaire , texte , intituleElement, idElement*/
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("PageUpdateDescription.Description.Entrée(idQuestionnaire : {0}, idElement{1})", model.idQuestionnaire, model.idElement));

            Elements element = new Elements();

            try
            {
                element = DALElement.FindById(model.idElement);
                model.idQuestionnaire = (int)element.questionnaire_id;
                model.texte           = element.texte;
                model.intituleElement = element.intitule;
                model.idElement       = element.Id;
                model.listeImagesUp   = DALMedia.SelectAllFromElement(element.Id);
                model.listeImagesDown = DALMedia.SelectAllFromElementDown(element.Id);
                model.video           = DALMedia.SelectVideoFromElement(element.Id);
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("PageUpdateDescription.Description.Exception(exception: {0})", e));
                return(RedirectToAction("PageCreateQuestionnaire", "Questionnaire", new{ id = model.idQuestionnaire, error = ErrorList.pageUpdateDescription }));
            }
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("PageUpdateDescription.Description.Sortie(idQuestionnaire : {0}, idElement{1})", model.idQuestionnaire, model.idElement));

            return(View(model));
        }
        public ActionResult RetourDescription(int idElement)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("retourDescription.UserQuestionnaire.Entrée(idElement : {0})", idElement));
            ViewModelUserQuestionnaire model = new ViewModelUserQuestionnaire();
            Elements element = new Elements();

            try
            {
                var el = DALElement.FindById(idElement);

                if (el.ordre <= 2)
                {
                    return(RedirectToAction("Index", "UserQuestionnaire"));
                }
                else
                {
                    //List<Elements> elements = ElementManager.SelectAllRetourDescriptionDesc(SessionManager.questionnaire.Id,ordre);
                    element          = DALElement.SelectElementRetourDescription(el);
                    model.element    = element;
                    model.imagesUp   = DALMedia.SelectAllFromElement(element.Id);
                    model.imagesDown = DALMedia.SelectAllFromElementDown(element.Id);
                    model.video      = DALMedia.SelectVideoFromElement(element.Id);
                }

                Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("retourDescription.UserQuestionnaire.Sortie(idElement retour : {0})", element.Id));
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("retourDescription.UserQuestionnaire.Exception(Exception : {0})", e));
                ViewBag.Error = ErrorList.retourDescription;
            }

            return(View(model));
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        public JsonResult DeleteVideoWithPath(int idVideo, String poth)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("deleteVideo.Media.Entrée(idVideo: {0})", idVideo));

            var videoPath = poth;

            var video = DALMedia.FindVideoById(idVideo);

            if (video != null)
            {
                try
                {
                    videoPath = videoPath + video.nom + "." + video.format;
                    DALMedia.DeleteVideo(video.Id);
                    if (System.IO.File.Exists(videoPath))
                    {
                        System.IO.File.Delete(videoPath);
                    }
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("deleteVideo.Media.Sortie(videoPath: {0})", videoPath));
                }
                catch (Exception e)
                {
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("deleteVideo.Media.Exception(Exception: {0})", e));
                    return(Json(ErrorList.deleteVideo));
                }
            }

            return(Json(1));
        }
Beispiel #6
0
        /**
         *  la position de l'image au dessus le texte est le 1 dans la colonne position
         *  public JsonResult AddImageUp(HttpPostedFileBase  file, int IdElement)
         */
        public JsonResult AddImageUp(HttpPostedFileBase file)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("AddImageUp.Media.Entrée(nom du fichier : {0})", file.FileName));

            var            newFileName = "";
            var            imagePath   = Path.Combine(Server.MapPath(Tools.ConfigHelper._CST_DIRECTORY_IMAGE));
            var            image       = new Images();
            var            idImage     = 0;
            ViewModelMedia model       = new ViewModelMedia();

            if (file != null)
            {
                try
                {
                    //La je dois recup l'Id de l'élément et je fais un substring sur le nom du fichier
                    var    y         = file.FileName;
                    string idElement = y.Substring(0, y.IndexOf("."));
                    newFileName = Guid.NewGuid().ToString() + "_" +
                                  Path.GetFileName(file.FileName);
                    image.format    = y.Substring(idElement.Length + 1);
                    image.nom       = newFileName.Substring(0, newFileName.IndexOf("."));
                    image.idelement = int.Parse(idElement);
                    var nbrImages = DALMedia.SelectAllFromElement(int.Parse(idElement)).Count();
                    image.ordre    = nbrImages + 2;
                    image.position = 1;
                    DALMedia.AddMediaUp(image);

                    imagePath = imagePath + image.nom + "." + image.format;
                    file.SaveAs(imagePath);

                    /**
                     * test avec la récup du nom de l'appli mais mes images ne sont pu afficher dans mon navigateur
                     */
                    //imagePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + @"\Content\images\" + image.nom + "." + image.format;
                    imagePath = Url.Content(Tools.ConfigHelper._CST_DIRECTORY_IMAGE + image.nom + "." + image.format);

                    model.imagePath = imagePath;
                    model.idImage   = image.Id;
                    idImage         = image.Id;
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("AddImageUp.Media.Sortie(imagePath : {0}, idImage : {1})", model.imagePath, model.idImage));
                }
                catch (Exception e)
                {
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("AddImageUp.Media.Exception(Exception : {0})", e));
                    return(Json(ErrorList.addImageUp));
                }
            }

            return(Json(model));
        }
Beispiel #7
0
        /**
         * Position image choix est le 3. Mais ça n'a pas grand intéret
         */
        public JsonResult AddImageChoix(HttpPostedFileBase file, int id)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("AddImageChoix.Media.Entrée(fileName : {0})", file.FileName));

            var            newFileName = "";
            var            imagePath   = Path.Combine(Server.MapPath(Tools.ConfigHelper._CST_DIRECTORY_IMAGE));
            var            image       = new Images();
            var            idImage     = 0;
            ViewModelMedia model       = new ViewModelMedia();

            if (file != null)
            {
                try
                {
                    //La je dois recup l'Id de l'élément et je fais un substring sur le nom du fichier
                    var    y       = file.FileName;
                    string idChoix = y.Substring(0, y.IndexOf("."));
                    newFileName = Guid.NewGuid().ToString() + "_" +
                                  Path.GetFileName(file.FileName);
                    image.format   = y.Substring(idChoix.Length + 1);
                    image.nom      = newFileName.Substring(0, newFileName.IndexOf("."));
                    image.idchoix  = int.Parse(idChoix);
                    image.position = 3;
                    DALMedia.AddMediaUp(image);
                    //TODO A voir le format du lien car ne marche pas
                    imagePath = imagePath + image.nom + "." + image.format;
                    file.SaveAs(imagePath);
                    imagePath = Url.Content(Tools.ConfigHelper._CST_DIRECTORY_IMAGE + image.nom + "." + image.format);
                    var choix = DALChoix.FindById(int.Parse(idChoix));
                    if (choix.image_id != null)
                    {
                        DeleteImage((int)choix.image_id);
                    }

                    choix.imagePath = Url.Content(Tools.ConfigHelper._CST_DIRECTORY_IMAGE + image.nom + "." + image.format);
                    choix.image_id  = image.Id;
                    DALChoix.UpdateChoix(choix);
                    model.imagePath = imagePath;
                    model.idImage   = image.Id;
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("AddImageChoix.Media.Sortie(imagePath : {0}, idImage : {1})", model.imagePath, model.idImage));
                }
                catch (Exception e)
                {
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("AddImageChoix.Media.Exception(Exception : {0})", e));
                    return(Json(ErrorList.addImageChoix));
                }
            }

            return(Json(model));
        }
Beispiel #8
0
        /**
         * La position de l'image est 2
         */
        public JsonResult AddImageDown(HttpPostedFileBase file)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("AddImageDown.Media.Entrée(fileName : {0})", file.FileName));

            var            newFileName = "";
            var            imagePath   = Path.Combine(Server.MapPath(Tools.ConfigHelper._CST_DIRECTORY_IMAGE));
            var            image       = new Images();
            var            idImage     = 0;
            ViewModelMedia model       = new ViewModelMedia();

            if (file != null)
            {
                try
                {
                    //La je dois recup l'Id de l'élément et je fais un substring sur le nom du fichier
                    var    y         = file.FileName;
                    string idElement = y.Substring(0, y.IndexOf("."));
                    newFileName = Guid.NewGuid().ToString() + "_" +
                                  Path.GetFileName(file.FileName);
                    image.format    = y.Substring(idElement.Length + 1);
                    image.nom       = newFileName.Substring(0, newFileName.IndexOf("."));
                    image.idelement = int.Parse(idElement);
                    var nbrImages = DALMedia.SelectAllFromElement(int.Parse(idElement)).Count();
                    image.ordre    = nbrImages + 2;
                    image.position = 2;
                    DALMedia.AddMediaUp(image);

                    imagePath = imagePath + image.nom + "." + image.format;
                    file.SaveAs(imagePath);
                    imagePath = Url.Content(Tools.ConfigHelper._CST_DIRECTORY_IMAGE + image.nom + "." + image.format);

                    model.imagePath = imagePath;
                    model.idImage   = image.Id;
                    idImage         = image.Id;
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("AddImageDown.Media.Sortie(imagePath : {0}, idImage : {1})", model.imagePath, model.idImage));
                }
                catch (Exception e)
                {
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("AddImage.Media.Exception(exception : {0})", e));
                    return(Json(ErrorList.addImageDown));
                }
            }

            return(Json(model));
        }
Beispiel #9
0
        /**
         * Fonction pour ajouter les vidéos
         */
        public JsonResult AddVideo(HttpPostedFileBase file)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("addVideo.Media.Entrée(fileName : {0})", file.FileName));

            var newFileName = "";
            var videoPath   = Path.Combine(Server.MapPath(Tools.ConfigHelper._CST_DIRECTORY_VIDEO));

            var            video   = new Videos();
            var            idImage = 0;
            ViewModelMedia model   = new ViewModelMedia();

            if (file != null)
            {
                try
                {
                    //La je dois recup l'Id de l'élément et je fais un substring sur le nom du fichier
                    var    y         = file.FileName;
                    string idElement = y.Substring(0, y.IndexOf("."));
                    newFileName = Guid.NewGuid().ToString() + "_" +
                                  Path.GetFileName(file.FileName);

                    video.format    = y.Substring(idElement.Length + 1);
                    video.nom       = newFileName.Substring(0, newFileName.IndexOf("."));
                    video.idelement = int.Parse(idElement);
                    videoPath       = videoPath + video.nom + "." + video.format;
                    file.SaveAs(videoPath);
                    DALMedia.AddVideoUp(video);
                    videoPath = Url.Content(Tools.ConfigHelper._CST_DIRECTORY_VIDEO + video.nom + "." + video.format);


                    model.videoPath   = videoPath;
                    model.idVideo     = video.Id;
                    model.formatVideo = video.format;
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("addVideo.Media.Sortie(idVideo : {0})", model.idVideo));
                }
                catch (Exception e)
                {
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("addVideo.Media.Exeption(exception : {0})", e));
                    return(Json(ErrorList.addVideo));
                }
            }

            return(Json(model));
        }
Beispiel #10
0
        /**
         * Delete question ave l'Id de la question
         */
        public ActionResult DeleteQuestion(int id)
        {
            MediaController med       = new MediaController();
            var             pothImage = Path.Combine(Server.MapPath(ConfigHelper._CST_DIRECTORY_IMAGE));

            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("DeleteQuestion.Question.Entrée(idElement : {0})", id));
            var idQuestionnaire = 0;

            try
            {
                Elements element = DALElement.FindById(id);
                idQuestionnaire = (int)element.questionnaire_id;
                if (DALMedia.SelectVeryAllFromElement(id) != null)
                {
                    foreach (var image in DALMedia.SelectVeryAllFromElement(id))
                    {
                        med.DeleteImage(image.Id, pothImage);
                    }
                }

                if (DALChoix.SelectAllByElement(id) != null)
                {
                    foreach (var choix in DALChoix.SelectAllByElement(id))
                    {
                        if (choix.image_id != null)
                        {
                            med.DeleteImage((int)choix.image_id, pothImage);
                        }
                    }
                }
                DALElement.DeleteElement(element.Id);
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("DeleteQuestion.Question.Sortie(idQuestionnaire: {0})", idQuestionnaire));
                return(RedirectToAction("PageCreateQuestionnaire", "Questionnaire", new { id = idQuestionnaire, erreur = ErrorList.deleteQuestion }));
            }

            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("DeleteQuestion.Question.Sortie(idQuestionnaire: {0})", idQuestionnaire));

            return(RedirectToAction("PageCreateQuestionnaire", "Questionnaire", new { id = idQuestionnaire }));
        }
        public ActionResult SuiteQuestion()
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("SuiteQuestion.UserQuestionnaire.Entrée(idElementSession: {0})", DALSession.element.Id));
            ViewModelUserQuestionnaire model = new ViewModelUserQuestionnaire();

            try
            {
                model.imagesUp       = DALMedia.SelectAllFromElement(DALSession.element.Id);
                model.listChoix      = DALChoix.SelectAllByElement(DALSession.element.Id);
                model.numeroQuestion = DALElement.FindNumeroQuestion(DALSession.element.Id);
                model.element        = DALSession.element;
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("SuiteQuestion.UserQuestionnaire.Exception(Excpetion : {0})", e));
                ViewBag.Error = ErrorList.suiteQuestion;
            }

            return(View(model));
        }
Beispiel #12
0
        public JsonResult ForwardImage(int idImage)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("forwrdImage.Media.Entrée(idImage: {0})", idImage));

            try
            {
                var image          = DALMedia.FindImageById(idImage);
                var imageApres     = DALMedia.ImageApres(image);
                var transfertOrdre = image.ordre;
                image.ordre      = imageApres.ordre;
                imageApres.ordre = transfertOrdre;
                DALMedia.UpdateImage(image);
                DALMedia.UpdateImage(imageApres);
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("forwrdImage.Media.Exception(Exception : {0})", e));
            }

            return(Json("hey"));
        }
Beispiel #13
0
        /**
         * Pour les fonction backward et forward j'inverse juste les numéro d'ordre des deux
         * image. Le reste est gérer en Jquery sur la partie front
         */
        public JsonResult BackwardImage(int idImage)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("backwardImage.Media.Entrée(idImage: {0})", idImage));
            try
            {
                var image          = DALMedia.FindImageById(idImage);
                var imageAvant     = DALMedia.ImageAvant(image);
                var transfertOrdre = image.ordre;
                image.ordre      = imageAvant.ordre;
                imageAvant.ordre = transfertOrdre;
                DALMedia.UpdateImage(image);
                DALMedia.UpdateImage(imageAvant);
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("backwardImage.Media.Sortie(imageAvantNouvalleOrdre {0}, imageNouvelleOrdre{1})", imageAvant.ordre, image.ordre));
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("backwardImage.Media.Exception(Exception : {0})", e));
            }


            return(Json("hey"));
        }
Beispiel #14
0
        /**
         * Efface la vidéo dans la base de donnée et dans le fichier sur le serveur
         */
        public JsonResult DeleteVideo(int idVideo, string poth = null)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("deleteVideo.Media.Entrée(idVideo: {0})", idVideo));
            string videoPath = null;

            if (poth != null)
            {
                videoPath = null;
            }
            else
            {
                videoPath = Path.Combine(Server.MapPath(Tools.ConfigHelper._CST_DIRECTORY_VIDEO));
            }

            var video = DALMedia.FindVideoById(idVideo);

            if (video != null)
            {
                try
                {
                    videoPath = videoPath + video.nom + "." + video.format;
                    DALMedia.DeleteVideo(video.Id);
                    if (System.IO.File.Exists(videoPath))
                    {
                        System.IO.File.Delete(videoPath);
                    }
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("deleteVideo.Media.Sortie(videoPath: {0})", videoPath));
                }
                catch (Exception e)
                {
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("deleteVideo.Media.Exception(Exception: {0})", e));
                    return(Json(ErrorList.deleteVideo));
                }
            }

            return(Json(1));
        }
Beispiel #15
0
        /**
         * Va effacer un élément puis réactualiser la page createQuestionnaire. Possible amélioration en
         * la mettant en Asyn avec Jquery
         */
        public ActionResult DeleteElement(int id)
        {
            MediaController med = new MediaController();

            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("DeleteDescription.Description.Entrée(idQuestionnaire : {0})", id));
            var      pothImage = Path.Combine(Server.MapPath(ConfigHelper._CST_DIRECTORY_IMAGE));
            var      pothVideo = Path.Combine(Server.MapPath(ConfigHelper._CST_DIRECTORY_VIDEO));
            Elements element   = new Elements();

            try
            {
                element = DALElement.FindById(id);
                if (DALMedia.SelectVeryAllFromElement(id) != null)
                {
                    foreach (var image in DALMedia.SelectVeryAllFromElement(id))
                    {
                        med.DeleteImage(image.Id, pothImage);
                    }
                }

                if (DALMedia.SelectVideoFromElement(id) != null)
                {
                    med.DeleteVideo(DALMedia.SelectVideoFromElement(id).Id, pothVideo);
                }
                DALElement.DeleteElement(element.Id);
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("DeleteDescription.Description.Exception(Exception : {0})", e));
                return(RedirectToAction("PageCreateQuestionnaire", "Questionnaire", new{ id = id, error = ErrorList.deleteDescription }));
            }

            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("DeleteDescription.Description.Sortie(idQuestionnaire : {0})", element.questionnaire_id));

            return(RedirectToAction("PageCreateQuestionnaire", "Questionnaire", new { id = element.questionnaire_id }));
        }
Beispiel #16
0
        /**
         * Page direct après création de la question ou en cliquant sur le bouton update Question
         */
        public ActionResult PageUpdateQuestion(int idElement)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("PageUpdateQuestion.Question.Entrée(idElement : {0})", idElement));

            ViewModelChoixQuestion model = new ViewModelChoixQuestion();

            try
            {
                model.element       = DALElement.FindById(idElement);
                model.listeImagesUp = DALMedia.SelectAllFromElement(idElement);
                model.listeChoix    = DALChoix.SelectAllByElement(idElement);
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("PageUpdateQuestion.QuestionException(idElement : {0}, exception : {1})", idElement, e));
                model.idQuestionnaire = 0;
                return(RedirectToAction("PageCreateQuestionnaire", "Questionnaire", new { erreur = ErrorList.PageUpdateQuestion }));
            }


            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("PageUpdateQuestion.Question.Sortie(element : {0})", Tools.JsonHelper.Serialize(model.element, typeof(Elements))));

            return(View("PageUpdateQuestion", model));
        }
Beispiel #17
0
        /**
         * Fonction delete appelé en Jquery
         */
        public JsonResult DeleteQuestionnaireJquery(int idQuestionnaire)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("DeleteQuestionnaire.Questionnaire.Entrée({0})", idQuestionnaire));
            MediaController med       = new MediaController();
            var             pothImage = Path.Combine(Server.MapPath(_CST_DIRECTORY_IMAGE));
            var             pothVideo = Path.Combine(Server.MapPath(_CST_DIRECTORY_VIDEO));

            try
            {
                var questionnaire = DALQuestionnaire.FindById(idQuestionnaire);
                if (DALElement.SelectAllQuestionFromQuestionnaire(idQuestionnaire) != null)
                {
                    var elements = DALElement.SelectAllFromQuestionnaire(idQuestionnaire);
                    foreach (var element in elements)
                    {
                        if (DALMedia.SelectAllFromElement(element.Id) != null)
                        {
                            var images = DALMedia.SelectAllFromElement(element.Id);
                            foreach (var image in images)
                            {
                                med.DeleteImage(image.Id, pothImage);
                            }
                        }

                        if (DALMedia.SelectVideoFromElement(element.Id) != null)
                        {
                            med.DeleteVideo(DALMedia.SelectVideoFromElement(element.Id).Id, pothVideo);
                        }

                        if (element.TypeElement_Id == 2)
                        {
                            if (DALChoix.SelectAllByElement(element.Id) != null)
                            {
                                var choix = DALChoix.SelectAllByElement(element.Id);
                                foreach (var c in choix)
                                {
                                    if (c.image_id != null)
                                    {
                                        med.DeleteImage((int)c.image_id, pothImage);
                                    }
                                }
                            }
                        }
                    }
                }
                DALQuestionnaire.DeleteQuestionnaire(idQuestionnaire);
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("DeleteQestionnaireJquery.Questionnaire.Exception(idquestionnaire : {0})", idQuestionnaire));
                //return RedirectToAction("ListeQuestionnaires", "Questionnaire", new { erreur = ErrorList.intituleQuestionnaire });
                return(Json(new
                {
                    redirectUrl = Url.Action("ListeQuestionnaires", "Questionnaire", new { erreur = ErrorList.deleteQuestionnaire }),
                    isRedirect = true
                }));
            }
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("DeleteQuestionnaire.Questionnaire.Sortie(idQuestionnaire : {0})", idQuestionnaire));

            return(Json(new
            {
                redirectUrl = Url.Action("ListeQuestionnaires", "Questionnaire"),
                isRedirect = true
            }));
        }
Beispiel #18
0
 public BLLMedia(DALConexao cx)
 {
     this.dalmedia = new DALMedia(cx);
 }
Beispiel #19
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));
        }