Example #1
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));
        }