public BookModel(Book book)
 {
     ID = book.ID;
     Name = book.Name;
     EditionYear = book.EditionYear;
     Publishing = book.Publishing;
     Pages = book.Pages;
     UDCID = book.UDCID;
 }
        // POST api/<controller>
        public HttpResponseMessage Post([FromBody]BookModel bookModel)
        {
            Book tranformedBook = new Book(bookModel);
            db.Books.Add(tranformedBook);
            db.SaveChanges();

            bookModel.ID = tranformedBook.ID;
            var response = Request.CreateResponse(HttpStatusCode.Created, bookModel);
            string url = Url.Link("DefaultApi", new { tranformedBook.ID });
            response.Headers.Location = new Uri(url);
            return response;
        }
        public ActionResult Create(Book book)
        {
            UDC udc = db.UDCs.FirstOrDefault(u => u.Code == book.UDC.Code);
            if (!book.isDateValid())
                ModelState.AddModelError("EditionYear", "Невірна дата публікації");
            if (!book.UDC.IsValid(db) || udc.Description == null || udc.Description == "")
            {
                ModelState.AddModelError("UDC.Code", "Невідомий УДК");
            }
            else
            {
                book.UDCID = udc.ID;
                book.UDC = udc;
            }

            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return RedirectToAction("Details", "Book", new { id = book.ID });
            }

            return View(book);
        }
        public ActionResult Edit(Book book)
        {
            if (!book.isDateValid())
                ModelState.AddModelError("EditionYear", "Невірна дата публікації");
            if (!book.UDC.IsValid(db))
            {
                ModelState.AddModelError("UDC.Code", "Невідомий УДК");
            }
            else
            {
                book.UDCID = db.UDCs.FirstOrDefault(u => u.Code == book.UDC.Code).ID;
                ModelState.SetModelValue("UDCID", new ValueProviderResult("",book.UDCID.ToString(), CultureInfo.CurrentCulture));
                ModelState.Remove("UDC");
                book.UDC = null;
            }

            if (ModelState.IsValid)
            {
                db.Entry(book).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Details", "Book", new{id = book.ID});
            }
            return View(book);
        }