Example #1
0
        public static bool DeleteVente(int articleID, int venteID)
        {
            using (var ctx = new GSMDBEntities())
            {

                var venteToRemove = ctx.Ventes.Where(v => v.Id.Equals(venteID) && v.Article.Id.Equals(articleID)).SingleOrDefault();
                ctx.Ventes.Remove(venteToRemove);
                return (ctx.SaveChanges() > 0);
            }
        }
Example #2
0
 public void TestAjouterArticle()
 {
     using (var ctx = new GSMDBEntities())
     {
         Article art = new Article();
         art.Désignation = "05 55 26 33 20";
         art.Type = "Puce Oooredoo";
         ctx.Articles.Add(art);
         int affectedRecords = ctx.SaveChanges();
         Assert.IsTrue(affectedRecords > 0);
     }
 }
Example #3
0
 public void TestAddVente()
 {
     using (var ctx = new GSMDBEntities())
     {
         var art = ctx.Articles.Where(a => a.Désignation.Equals("05 55 26 33 20")).SingleOrDefault();
         Vente v = new Vente()
         {
             ArticleId = art.Id,
             DateVente = DateTime.Now.AddDays(-1),
             MontantVente = 10000
         };
         art.Ventes.Add(v);
         int count = ctx.SaveChanges();
         Assert.IsTrue(count != 0 && v.Id != 0);
     }
 }
Example #4
0
 public static ArticleDTO SaveArticle(ArticleDTO a)
 {
     GSMEF.Article EA = Article.ConvertFromDTO(a);
     using (var ctx = new GSMDBEntities())
     {
         if (EA.Id > 0)
         {
             ctx.Entry(EA).State = System.Data.Entity.EntityState.Modified;
             foreach (var child in EA.Ventes)
             {
                 ctx.Entry(child).State = System.Data.Entity.EntityState.Modified;
                 ctx.SaveChanges();
             }
         }
         else
         {
             EA = Article.ConvertFromDTO(a);
             ctx.Articles.Add(EA);
             a.Id = EA.Id;
             //because of DTOs we need to firm upthe FKs
             foreach (var child in a.VentesDto)
             {
                 child.ArticleId = a.Id;
             }
         }
     }
     return a;
 }