//==========SELECTS=================// /// Recuperer un commentaire specifique public static CommentairesProduit GetById(int pId, MontRealEstateEntities pDb = null) { bool dbEstNull = false; if (pDb == null) { pDb = new MontRealEstateEntities(); dbEstNull = true; } CommentairesProduit rValue = pDb.CommentairesProduits.Where(m => m.Id == pId && m.EstSupprime == false).FirstOrDefault(); if (dbEstNull) { pDb.Dispose(); } return(rValue); }
//==========DELETES=================// /// Supprimer tous les commentaires d'un produit public static bool DeleteById(int pComId) { bool retour = false; if (pComId > 0) { using (MontRealEstateEntities db = new MontRealEstateEntities()) { CommentairesProduit commentairesProd = GetById(pComId, db); if (commentairesProd != null) { commentairesProd.EstSupprime = true; commentairesProd.DateModification = DateTime.Now; Outils.ConnectWebSecurity(); commentairesProd.ModifiePar = WebSecurity.CurrentUserId; db.SaveChanges(); retour = true; } } } return(retour); }
//==========INSERTS ET UPDATES=================// public static void Save(CommentairesProduit pModel) { using (MontRealEstateEntities db = new MontRealEstateEntities()) { //modification if (pModel.Id > 0) { CommentairesProduit commentProdModifier = GetById(pModel.Id, db); commentProdModifier.Commentaires = pModel.Commentaires; commentProdModifier.DateModification = DateTime.Now; commentProdModifier.ModifiePar = pModel.ModifiePar; } else { //add pModel.DateCreation = DateTime.Now; pModel.DateModification = DateTime.Now; db.CommentairesProduits.AddObject(pModel); } //enregistrer les modifications db.SaveChanges(); } }