/// <summary> /// Saves a new product. /// </summary> /// <param name="product"></param> /// <returns></returns> public Stable Save(Stable stable) { // Read in the existing products List <Stable> stables = Retrieve().ToList(); // Assign a new Id var maxId = stables.Max(s => s.Id); stable.Id = maxId + 1; stables.Add(stable); WriteData(stables); return(stable); }
/// <summary> /// Updates an existing product /// </summary> /// <param name="id"></param> /// <param name="product"></param> /// <returns></returns> public Stable Save(int id, Stable stable) { // Read in the existing products List <Stable> stables = Retrieve().ToList(); // Locate and replace the item var itemIndex = stables.FindIndex(s => s.Id == stable.Id); if (itemIndex >= 0) { stables[itemIndex] = stable; } else { return(null); } WriteData(stables); return(stable); }