示例#1
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));
        }
示例#2
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));
        }
示例#3
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));
        }
示例#4
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));
        }