public ActionResult Pack(int?id, string name, decimal amount, decimal cost, int group, int costMin) { Pack pack = _db.Packs.Include(p => p.Stock).FirstOrDefault(p => p.Id == id); IEnumerable <Greenhouse> gh1 = _db.Greenhouses .Include(g => g.PacksForGH) .Include(g => g.Stock) .Where(g => g.Stock.Id == pack.Stock.Id); foreach (var g in gh1) { PackForGH p1 = null; p1 = g.PacksForGH.FirstOrDefault(p => p.Name == pack.Name); if (p1 != null) { p1.Name = name; p1.Cost = cost; } } pack.Name = name; pack.Amount = amount; pack.Cost = cost; pack.Group = group; pack.CostMin = costMin; _db.SaveChanges(); return(RedirectToAction("Index", "Admin")); }
public ActionResult Ticket(int?id) { Claim claim = db.Claims .Include(s => s.GreenhouseForSales) .Include(s => s.Stock) .FirstOrDefault(s => s.Id == id); List <PackForGH> packs = new List <PackForGH>(); foreach (var g in claim.GreenhouseForSales) { Greenhouse prod = db.Greenhouses .Include(x => x.PacksForGH) .Include(x => x.Stock) .FirstOrDefault(x => x.Name == g.Name && x.Stock.Id == claim.Stock.Id); foreach (var p in prod.PacksForGH) { decimal buf = p.Amount; p.Amount = p.Amount * g.Amount; if (p.Amount > 0) { PackForGH pfg = null; pfg = packs.FirstOrDefault(x => x.Name == p.Name); if (pfg == null) { packs.Add(new PackForGH() { Name = p.Name, Amount = p.Amount, Cost = p.Cost, GreenHouse = p.GreenHouse }); } else { pfg.Amount += p.Amount; } } p.Amount = buf; } } ViewBag.Packs = packs; return(View(claim)); }
public ActionResult PackDelete(int?id) { Pack pack = _db.Packs.Include(p => p.Stock).FirstOrDefault(p => p.Id == id); IEnumerable <Greenhouse> gh1 = _db.Greenhouses .Include(g => g.PacksForGH) .Include(g => g.Stock) .Where(g => g.Stock.Id == pack.Stock.Id); foreach (var g in gh1) { PackForGH p1 = null; p1 = g.PacksForGH.FirstOrDefault(p => p.Name == pack.Name); if (p1 != null) { _db.PacksForGh.Remove(p1); } } _db.Packs.Remove(pack); _db.SaveChanges(); return(RedirectToAction("Index", "Admin")); }