Ejemplo n.º 1
0
        public ActionResult Index()
        {
            List <projet> listeProjets = dal.ObtenirTousLesProjets();

            List <DisplayInformationCatalogue> ListeDIC = new List <DisplayInformationCatalogue>();

            foreach (projet monProjet in listeProjets)
            {
                medium monMedia = dal.GetId_Media(monProjet.id_projet);
                if (monMedia == null)
                {
                    continue;
                }
                ListeDIC.Add(new DisplayInformationCatalogue
                {
                    Id_projet   = monProjet.id_projet,
                    Libelle     = monProjet.libelle,
                    Description = monProjet.description,
                    Id_media    = monMedia.id_media,
                    Lib_image   = monMedia.lib_image
                });
            }

            return(View(ListeDIC));
        }
        public ActionResult CreateMedia(medium createMedia, HttpPostedFileBase fileToUpload)
        {
            if (ModelState.IsValid)
            {
                if (createMedia.lib_image == null)
                {
                    return(Redirect("/media/index?id=" + createMedia.id_projet + "&err=err1"));
                }

                int tstimage = dalCProj.GetId_Media_all(createMedia.id_projet, createMedia.lib_image);
                if (tstimage != -1)
                {
                    return(Redirect("/media/index?id=" + createMedia.id_projet + "&err=errl" + createMedia.lib_image));
                }

                if (fileToUpload == null)
                {
                    return(Redirect("/media/index?id=" + createMedia.id_projet + "&err=errf"));
                }

                if (fileToUpload.ContentLength > 500000)
                {
                    return(Redirect("/media/index?id=" + createMedia.id_projet + "&err=errfl"));
                }

                if (fileToUpload.ContentLength > 0)
                {
                    // convert file choose by user into byte[]
                    byte[] imagePrincipale = null;
                    using (var binaryReader = new BinaryReader(fileToUpload.InputStream))
                    {
                        imagePrincipale = binaryReader.ReadBytes(fileToUpload.ContentLength);
                    }

                    dalCProj.AddMedia(imagePrincipale, null, createMedia.id_projet, "JPG", createMedia.lib_image);
                }

                // Ramener Idprojet et libImage

                return(RedirectToAction("Index", new { id = createMedia.id_projet }));
            }
            return(View(createMedia));
        }
Ejemplo n.º 3
0
 private Media(medium mediaData)
     : base()
 {
     MapProperties(this, mediaData);
 }
        // GET: Media
        public ActionResult Index(int?id, string err)
        {
            if (id.HasValue)
            {
                // recuperation infos sur projer
                projet monprojet = dalCProj.get_Projet(id.Value);
                if (monprojet == null)
                {
                    return(View("Erreur"));
                }

                ViewBag.monprojet = monprojet;

                // Recuperation infos sur Medias principal
                ViewBag.monmedia = dalCProj.GetId_Media(id.Value);

                // recuperation des autres images projets
                ViewBag.image2 = dalCProj.GetId_Media_all(id.Value, "image_2");
                ViewBag.image3 = dalCProj.GetId_Media_all(id.Value, "image_3");
                ViewBag.image4 = dalCProj.GetId_Media_all(id.Value, "image_4");

                // message d'erreur
                string libsel   = "principale";
                string msgLibel = "";
                string msgfile  = "";
                if (err != null)
                {
                    if (err == "err1")
                    {
                        msgLibel = "Séléctionnez un libelle valide";
                        libsel   = null;
                    }
                    else if (err.Substring(0, 4) == "errl")
                    {
                        string zonerr = err.Substring(4);

                        msgLibel = "Il y a déjà une image pour le libellé " + zonerr;
                        libsel   = zonerr;
                    }
                    else if (err == "errf")
                    {
                        msgfile = "Pas de fichier selectionné pour le téléchargement";
                    }
                    else if (err == "errfl")
                    {
                        msgfile = "fichier selectionné trop volumineux";
                    }
                }
                ViewBag.errlibel = msgLibel;
                ViewBag.errfile  = msgfile;

                SelectList maListe = new SelectList(
                    new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "Principale", Value = "Principale"
                    },
                    new SelectListItem {
                        Text = "Image 2", Value = "Image_2"
                    },
                    new SelectListItem {
                        Text = "Image 3", Value = "Image_3"
                    },
                    new SelectListItem {
                        Text = "Image 4", Value = "Image_4"
                    },
                }, "Value", "Text");

                ViewBag.LibImage = maListe;

                // ViewBag.monId = (int)id;

                medium monMedia = new medium()
                {
                    id_media   = -1,
                    id_projet  = id.Value,
                    lien       = null,
                    media      = null,
                    type_media = "JPEG",
                    lib_image  = libsel
                };

                return(View(monMedia));
            }
            else
            {
                return(View("Erreur"));
            }
        }