public HttpResponseMessage PutBook(Book book) { try { bs.Update(book); } catch (BookStorage.NotFoundException) { return ErrorMessage(HttpStatusCode.NotFound, "Requested id is not found in the storage"); } return ErrorMessage(HttpStatusCode.OK, "updated"); }
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 HttpResponseMessage PostBook(Book book) { bs.Add(book); return ErrorMessage(HttpStatusCode.OK, "added"); }
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; } }