Esempio n. 1
0
        public static bool SavePhotoProduitServer(Produit pProd, HttpServerUtilityBase Server, bool isProfile)
        {
            try
            {
                if (isProfile)
                {
                    //effacer la photo de profile
                    PhotosProduit photoProfile = PhotosProduit.GetPhotoProfilByProduitId(pProd.Id);

                    if (photoProfile != null)
                    {
                        PhotosProduit.Delete(photoProfile.Id);
                    }
                }
                if (pProd.NbPhotosMax > PhotosProduit.CountNbPhotosProduit(pProd.Id))
                {
                    string path2 = System.Guid.NewGuid().ToString() + pProd.Fichier.FileName;
                    string path  = Path.Combine(Server.MapPath("~/Images/PhotosProduits"), path2);
                    pProd.Fichier.SaveAs(path);
                    string URL = "/Images/PhotosProduits" + path2;

                    PhotosProduit nouvPhoto = new PhotosProduit();
                    nouvPhoto.EstSupprime = false;
                    nouvPhoto.ModifiePar  = WebSecurity.CurrentUserId;
                    nouvPhoto.ProduitId   = pProd.Id;
                    nouvPhoto.URLPhoto    = URL;
                    nouvPhoto.EstProfil   = isProfile;

                    PhotosProduit.SavePhotoProduit(nouvPhoto);
                    return(true);
                }
                else
                {
                    return(false); //max photos
                }
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
 //delete photo et retourne vers les details de l'imeuble
 public ActionResult Delete(int pIdPhoto, int pIdProd)
 {
     PhotosProduit.Delete(pIdPhoto);
     return(RedirectToAction("DetailProduit", "Produit", new { pId = pIdProd }));
 }