public List <Categorie> GetAll() { using (var context = new MyPlaceContext()) { return(context.categorie.ToList()); } }
public Categorie Get(int?id) { using (var context = new MyPlaceContext()) { return(context.categorie.Find(id)); } }
public Commande Get(int?id) { using (var context = new MyPlaceContext()) { return(context.commande.Include(i => i.DetailCommande.Select(c => c.Produit.Categorie)).Where(i => i.Id == id).FirstOrDefault()); } }
public void Save(Commande commande) { using (var context = new MyPlaceContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { context.commande.Add(commande); foreach (var detail in commande.DetailCommande) { Produit p = context.produit.Find(detail.ProduitId); if (p != null) { p.QuantiteStock = p.QuantiteStock - detail.Quantite; } else { commande.DetailCommande.Remove(detail); } } context.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); throw; } } } }
public Produit Get(int?id) { using (var context = new MyPlaceContext()) { return(context.produit.Include(p => p.Categorie).Where(p => p.Id == id).FirstOrDefault()); } }
public List <Commande> GetAll() { using (var context = new MyPlaceContext()) { return(context.commande.ToList()); } }
public List <Produit> GetAll() { using (var context = new MyPlaceContext()) { return(context.produit.Include(p => p.Categorie).ToList()); } }
public BaseModelPagination <Categorie> GetAll(int page = 1, int maxResult = 10) { using (var context = new MyPlaceContext()) { BaseModelPagination <Categorie> pagination = new BaseModelPagination <Categorie>(page, maxResult); pagination.totalResult = context.categorie.Count(); pagination.liste = context.categorie.OrderBy(i => i.Id).Skip(pagination.offset()).Take(maxResult).ToList(); return(pagination); } }
public void Update(Commande commande) { using (var context = new MyPlaceContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { HashSet <int> selected = new HashSet <int>(); if (commande.DetailCommande == null) { commande.DetailCommande = new HashSet <DetailCommande>(); } else { foreach (DetailCommande item in commande.DetailCommande) { selected.Add(item.ProduitId); if (item.Quantite <= 0) { context.Entry(item).State = EntityState.Deleted; } else if (item.CommandeId != commande.Id) { item.CommandeId = commande.Id; context.Entry(item).State = EntityState.Added; } else { context.Entry(item).State = EntityState.Modified; } } } var old = context.detailCommande.Where(dc => dc.CommandeId == commande.Id && !selected.Contains(dc.ProduitId)).ToList(); old.ForEach(x => context.Entry(x).State = EntityState.Deleted); context.Entry(commande).State = EntityState.Modified; context.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); foreach (DetailCommande item in commande.DetailCommande) { context.Entry(item).Reference(dc => dc.Produit).Load(); } throw; } } } }
public ActionResult Administrateur() { using (var context = new MyPlaceContext()) { using (var usercontext = new ApplicationDbContext()) { ViewBag.Categorie = context.categorie.Count(); ViewBag.Commande = context.commande.Count(); ViewBag.Produit = context.produit.Count(); ViewBag.Utilisateur = usercontext.Users.Count(); return(View()); } } }
public void Update(Categorie categorie) { using (var context = new MyPlaceContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { context.Entry(categorie).State = EntityState.Modified; context.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); throw; } } } }
public void Save(Categorie categorie) { using (var context = new MyPlaceContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { context.categorie.Add(categorie); context.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); throw; } } } }
public void Save(Produit produit) { using (var context = new MyPlaceContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { context.produit.Add(produit); context.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); throw; } } } }
public void Delete(int id) { using (var context = new MyPlaceContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { Categorie categorie = context.categorie.Find(id); context.categorie.Remove(categorie); context.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); throw; } } } }
public void Delete(int id) { using (var context = new MyPlaceContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { Produit produit = context.produit.Find(id); context.produit.Remove(produit); context.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); throw; } } } }
public BaseModelPagination <Produit> FindAllDisponible(int categorie, string query, int page = 1, int maxResult = 10) { using (var context = new MyPlaceContext()) { BaseModelPagination <Produit> pagination = new BaseModelPagination <Produit>(page, maxResult); IQueryable <Produit> queryable = context.produit.Include(p => p.Categorie).Where(p => p.QuantiteStock > 0); if (!string.IsNullOrWhiteSpace(query)) { queryable = queryable.Where(p => p.Nom.ToLower().Contains(query.ToLower())); } if (categorie > 0) { queryable = queryable.Where(p => p.CategorieId == categorie); } pagination.liste = queryable.OrderBy(i => i.Nom) .Skip(pagination.offset()) .Take(maxResult) .ToList(); pagination.totalResult = queryable.Count(); return(pagination); } }