コード例 #1
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));
        }
コード例 #2
0
        public JsonResult UpdateChoix(ViewModelChoixQuestion model)
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("updateChoix.Choix.Entrée(idElement: {0})", model.idElement));

            int idChoixRetour = 0;

            try
            {
                var choix = DALChoix.FindById(model.idChoix);
                choix.intitule = model.intituleChoix;
                choix.statut   = model.statutChoix;
                DALChoix.UpdateChoix(choix);
                idChoixRetour = choix.Id;
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Info, string.Format("updateChoix.Choix.Sortie(idChoix: {0})", choix.Id));
            }
            catch (Exception e)
            {
                Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur, string.Format("insertChoix.Choix.Exception(Exception : {0})", e));
                return(Json(ErrorList.updateChoix));
            }



            return(Json(idChoixRetour));
        }
コード例 #3
0
        public JsonResult InsertChoix(ViewModelChoixQuestion model)/*idElement*/
        {
            Tools.Logger.Ecrire(Tools.Logger.Niveau.Info,
                                string.Format("InsertChoix.Choix.Entrée(idElement: {0})", model.idElement));

            int idChoixRetour = 0;

            if (model.idElement != null)
            {
                try
                {
                    Choixes choix = new Choixes();
                    choix.element_id = model.idElement;
                    choix.statut     = false;
                    DALChoix.InsertChoix(choix);
                    idChoixRetour = choix.Id;
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Info,
                                        string.Format("insertChoix.Choix.Sortie(idChoix: {0})", choix.Id));
                }
                catch (Exception e)
                {
                    Tools.Logger.Ecrire(Tools.Logger.Niveau.Erreur,
                                        string.Format("insertChoix.Choix.Exception(exception : {0})", e));
                    return(Json(ErrorList.insertChoix));
                }
            }
            return(Json(idChoixRetour));
        }
コード例 #4
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));
        }
コード例 #5
0
ファイル: QuestionController.cs プロジェクト: blajib/QCM
        /**
         * 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 }));
        }
コード例 #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
ファイル: QuestionController.cs プロジェクト: blajib/QCM
        /**
         * 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
ファイル: QuestionnaireController.cs プロジェクト: blajib/QCM
        /**
         * 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));
        }