Example #1
0
 public ActionResult OnPost()
 {
     if (ModelState.IsValid == false)
     {
         return(Page());
     }
     Rechnung.Id = int.Parse(RouteData.Values["id"].ToString());
     //   Rechnung.Summe = _ef.Positionen.Where(x => x.RechnungID == Rechnung.Id).ToList().Sum(y => y.Preis * y.Anzahl).Value;
     _ef.Rechnung.Attach(Rechnung).State = EntityState.Modified;
     _ef.SaveChanges();
     ModelState.AddModelError("hannes", "super erfolgreich gespeichert");
     return(Page());
 }
Example #2
0
        public void OnGet([FromServices]  ERPModel2 ef)
        {
            var rand = new Random();

            for (int i = 0; i < 100; i++)
            {
                var r = new Rechnung()
                {
                    Datum = DateTime.Now.AddDays(rand.Next(300)), KundenID = rand.Next(100000)
                };
                for (int ii = 1; ii < rand.Next(5); ii++)
                {
                    r.Positionen.Add(new Positionen()
                    {
                        Anzahl = rand.Next(3), Preis = rand.Next(99), Text = "demo" + rand.Next(10000).ToString()
                    });
                }

                r.Summe = r.Positionen.Sum(x => x.Anzahl * x.Preis);
                ef.Rechnung.Add(r);
                ef.SaveChanges();
            }
        }