public Pantry RemovePantry(Pantry pantry) { var toUpdate = _pantries.Find(s => s.Id.Equals(pantry.Id)); if (toUpdate != null) { toUpdate.State = TrackingState.Deleted; return(pantry); } return(null); }
public Pantry AddNewPantry(Pantry pantry) { if (_pantries.Any(s => s.Id.Equals(pantry.Id))) { throw new ArgumentException("Cannot add duplicate pantry to office."); } if (_pantries.Any(s => s.Name.Equals(pantry.Name, StringComparison.InvariantCultureIgnoreCase))) { throw new ArgumentException("Cannot add pantry to office."); } pantry.State = TrackingState.Added; _pantries.Add(pantry); return(pantry); }
public Pantry UpdatePantry(Pantry pantry) { if (_pantries.Any(s => s.Name.Equals(pantry.Name, StringComparison.InvariantCultureIgnoreCase) && !s.Id.Equals(pantry.Id))) { throw new ArgumentException("This pantry name already exists, please specify a different name."); } var toUpdate = _pantries.Find(s => s.Id.Equals(pantry.Id)); if (toUpdate != null) { toUpdate.Name = pantry.Name; toUpdate.State = TrackingState.Modified; return(pantry); } return(null); }