Пример #1
0
        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));
        }
Пример #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));
        }
Пример #3
0
        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));
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
0
        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));
        }
Пример #7
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));
        }
Пример #8
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
            }));
        }
Пример #9
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));
        }