public void AddOrUpdate(Matratt dish) { if (dish.MatrattId != 0) { Matratt oldDish = _dbContext.Matratt.Include(d => d.MatrattProdukt) .Single(d => d.MatrattId == dish.MatrattId); oldDish.MatrattProdukt.Clear(); _dbContext.SaveChanges(); oldDish.MatrattNamn = dish.MatrattNamn; oldDish.MatrattProdukt = dish.MatrattProdukt; oldDish.MatrattTyp = dish.MatrattTyp; oldDish.Beskrivning = dish.Beskrivning; oldDish.Pris = dish.Pris; _dbContext.AttachRange(oldDish.MatrattProdukt.Select(dp => dp.Produkt)); _dbContext.SaveChanges(); } else { _dbContext.AttachRange(dish.MatrattProdukt.Select(dp => dp.Produkt)); _dbContext.Matratt.Add(dish); _dbContext.SaveChanges(); } }
public virtual void AddItem(Matratt dish, int quantity) { CartLine line = lineCollection .Where(cl => cl.Dish.MatrattId == dish.MatrattId) .FirstOrDefault(); if (line == null) { lineCollection.Add(new CartLine { Dish = dish, Quantity = quantity }); } else { line.Quantity += quantity; } }
public virtual void RemoveLine(Matratt dish) => lineCollection.RemoveAll(l => l.Dish.MatrattId == dish.MatrattId);
public override void RemoveLine(Matratt dish) { base.RemoveLine(dish); Session.SetJson("Cart", this); }
public override void AddItem(Matratt dish, int quantity) { base.AddItem(dish, quantity); Session.SetJson("Cart", this); }