示例#1
0
        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);
        }
示例#2
0
 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);
 }
示例#3
0
        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);
        }