public void Add(Book b) { string result = BookFields.Validate(b); if (result != null) { throw new ValidationException(result); } lock (lockObj) { b.id = lastId + 1; books.Add(b.id, (Book)b.Clone()); books[b.id].image = b.image; lastId++; } }
public void Update(Book b) { string result = BookFields.Validate(b); if (result != null) { throw new ValidationException(result); } lock (lockObj) { if (!books.ContainsKey(b.id)) { throw new NotFoundException(); } var clone = (Book)b.Clone(); clone.image = (b.image != null && b.image.Length > 0) ? b.image : books[b.id].image; books[b.id] = clone; } }