public void DeletePrice(long id) { var oldPrice = Prices.FirstOrDefault(@class => @class.Id == id); Prices.Remove(oldPrice); var newPriceChange = new PriceChangeClass { Action = "Delete", Id = oldPrice.Id, ItemName = oldPrice.ItemName, Price = 0, priceWas = oldPrice.Price }; PriceChanges.Add(newPriceChange); Utils.SaveToFile(); }
public void PostNewPrice(PriceClass price) { if (price.Id == 0) { var newId = Prices.Select(@class => @class.Id).Max() + 1; price.Id = newId; Prices.Add(price); var newPriceChange = new PriceChangeClass { Action = "New", Id = price.Id, ItemName = price.ItemName, Price = price.Price, priceWas = 0 }; PriceChanges.Add(newPriceChange); } else { var oldPrice = Prices.FirstOrDefault(@class => @class.Id == price.Id); Prices.Remove(oldPrice); Prices.Add(price); var newPriceChange = new PriceChangeClass { Action = "Edit", Id = price.Id, ItemName = price.ItemName, Price = price.Price, priceWas = oldPrice.Price }; PriceChanges.Add(newPriceChange); } Utils.SaveToFile(); }