예제 #1
0
 public virtual T GetSingle(int id)
 {
     using (var ctx = new ErpContext())
     {
         return ctx.Set<T>().Find(id);
     }
 }
예제 #2
0
 public virtual void Update(T obj)
 {
     using (var ctx = new ErpContext())
     {
         ctx.Set<T>().AddOrUpdate(obj);
         ctx.SaveChanges();
     }
 }
예제 #3
0
 public virtual void Remove(int id)
 {
     using (var ctx = new ErpContext())
     {
         var obj = ctx.Set<T>().Find(id);
         ctx.Set<T>().Remove(obj);
         ctx.SaveChanges();
     }
 }
예제 #4
0
 public virtual T Create(T obj)
 {
     using (var ctx = new ErpContext())
     {
         var newObj = ctx.Set<T>().Add(obj);
         ctx.SaveChanges();
         return newObj;
     }
 }
예제 #5
0
 public override lagerposition GetSingle(int id)
 {
     using (var ctx = new ErpContext())
     {
         return(ctx.lagerposition
                .Include(l => l.lager)
                .FirstOrDefault(b => b.Id == id));
     }
 }
예제 #6
0
 public override kunde GetSingle(int id)
 {
     using (var ctx = new ErpContext())
     {
         return(ctx.kunde
                .Include(l => l.person)
                .FirstOrDefault(b => b.Id == id));
     }
 }
예제 #7
0
        public virtual List<T> GetAll(Func<T, bool> where = null)
        {
            using (var ctx = new ErpContext())
            {
                List<T> baseQuery = ctx.Set<T>().ToList();

                if (where != null)
                    baseQuery = baseQuery.Where(where).ToList(); // running filter in-memory, because of non-db fields like displayname's etc.

                return baseQuery.ToList();
            }
        }
예제 #8
0
 public override bestellung GetSingle(int id)
 {
     using (var ctx = new ErpContext())
     {
         return(ctx.bestellung
                .Include(b => b.kunde.person)
                .Include(b => b.bestellposition.Select(p => p.artikel))
                .Include(b => b.bestellposition.Select(p => p.kundenpreis))
                .Include(b => b.bestellposition.Select(p => p.lagerposition.lager))
                .FirstOrDefault(b => b.Id == id));
     }
 }
예제 #9
0
        public override List <kunde> GetAll(Func <kunde, bool> where = null)
        {
            using (var ctx = new ErpContext())
            {
                IEnumerable <kunde> baseQuery = ctx.kunde
                                                .Include(x => x.person).ToList();

                if (where != null)
                {
                    baseQuery = baseQuery.Where(where);
                }

                return(baseQuery.ToList());
            }
        }
예제 #10
0
        public override List <lagerposition> GetAll(Func <lagerposition, bool> where = null)
        {
            using (var ctx = new ErpContext())
            {
                IEnumerable <lagerposition> baseQuery = ctx.lagerposition
                                                        .Include(x => x.lager).ToList();

                if (where != null)
                {
                    baseQuery = baseQuery.Where(where);
                }

                return(baseQuery.ToList());
            }
        }
예제 #11
0
        public override List <bestellung> GetAll(Func <bestellung, bool> where = null)
        {
            using (var ctx = new ErpContext())
            {
                var baseQuery = ctx.bestellung
                                .Include(x => x.kunde.person)
                                .Include(b => b.bestellposition).ToList();

                if (where != null)
                {
                    baseQuery = baseQuery.Where(where).ToList();
                }

                return(baseQuery.ToList());
            }
        }
예제 #12
0
        public override void Remove(int id)
        {
            using (var ctx = new ErpContext())
            {
                var obj = ctx.bestellung.Find(id);

                ctx.Entry(obj).Reload();
                ctx.Entry(obj).Collection(b => b.lieferschein).Load();
                ctx.Entry(obj).Collection(b => b.bestellposition).Load();

                ctx.lieferschein.RemoveRange(obj.lieferschein);
                ctx.bestellposition.RemoveRange(obj.bestellposition);

                ctx.bestellung.Remove(obj);
                ctx.SaveChanges();
            }
        }
        public override List <bestellposition> GetAll(Func <bestellposition, bool> where = null)
        {
            using (var ctx = new ErpContext())
            {
                IEnumerable <bestellposition> baseQuery = ctx.bestellposition
                                                          .Include(b => b.artikel)
                                                          .Include(b => b.bestellung)
                                                          .Include(b => b.kundenpreis)
                                                          .Include(b => b.lagerposition);

                if (where != null)
                {
                    baseQuery = baseQuery.Where(where);
                }

                return(baseQuery.ToList());
            }
        }
        private bestellposition AddOrUpdateBestellposition(bestellposition p)
        {
            using (var ctx = new ErpContext())
            {
                p.bestellung    = ctx.bestellung.Find(p.bestellung.Id);
                p.artikel       = ctx.artikel.Find(p.artikel.Id);
                p.lagerposition = ctx.lagerposition.Find(p.lagerposition.Id);

                if (!HasKundenPreis(p) && p.kundenpreis.Rabatt > 0)
                {
                    var kundenPreis = p.kundenpreis;
                    kundenPreis.artikel  = p.artikel;
                    kundenPreis.kunde    = p.bestellung.kunde;
                    kundenPreis.Waehrung = "CHF";

                    ctx.kundenpreis.Add(kundenPreis);
                    ctx.SaveChanges();

                    p.kundenpreis = ctx.kundenpreis.Find(p.kundenpreis.Id);
                    p.fk_Bestellposition_KundenPreis = p.kundenpreis.Id;
                }
                else if (p.fk_Bestellposition_KundenPreis > 0)
                {
                    ctx.kundenpreis.AddOrUpdate(p.kundenpreis);
                    ctx.SaveChanges();
                }
                else
                {
                    p.kundenpreis = null;
                }

                ctx.bestellposition.AddOrUpdate(p);

                ctx.SaveChanges();
                return(GetSingle(p.Id));
            }
        }