Example #1
0
        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");
        }
Example #2
0
        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++;
            }
        }
Example #3
0
 public HttpResponseMessage PostBook(Book book)
 {
     bs.Add(book);
     return ErrorMessage(HttpStatusCode.OK, "added");
 }
Example #4
0
        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;
            }
        }