public TranslatedBook Patch(string id, Book patch)
		{
			var book = _db.Books.Include(c => c.Translations).SingleOrDefault(c => c.Id == id);

			book.Patch(patch);

			return new TranslatedBook(book);
		}
		public TranslatedBook(Book book)
		{
			Id = book.Id;
			Author = book.Author;
			if (book.Translations != null && book.Translations.Any())
			{
				var translation = book.Translations.First();
				Culture = translation.Culture;
				Title = translation.Title;
				Description = translation.Description;
				PublishDate = translation.PublishDate;
				ISBN10 = translation.ISBN10;
				ISBN13 = translation.ISBN13;
				Publisher = translation.Publisher;
				PagesCount = translation.PagesCount;
				FormatType = translation.FormatType;
				CoverImage = translation.CoverImage;
				AmazonUrl = translation.AmazonUrl;
				Tags = translation.Tags;
			}
		}
Exemple #3
0
		public void Patch(Book patch)
		{
			if (patch.Author?.Name != null) Author.Name = patch.Author.Name;
			if (patch.Author?.Url != null) Author.Name = patch.Author.Url;
			if (patch.Author?.Photo != null) Author.Name = patch.Author.Photo;
			foreach (var translationPatch in patch.Translations)
			{
				var translation = Translations.FirstOrDefault(t => t.Culture == translationPatch.Culture);
				if (translation == null) { continue; }

				if (translationPatch.Title != null) translation.Title = translationPatch.Title;
				if (translationPatch.Description != null) translation.Description = translationPatch.Description;
				if (translationPatch.PublishDate != null) translation.PublishDate = translationPatch.PublishDate;
				if (translationPatch.ISBN10 != null) translation.ISBN10 = translationPatch.ISBN10;
				if (translationPatch.ISBN13 != null) translation.ISBN13 = translationPatch.ISBN13;
				if (translationPatch.Publisher != null) translation.Publisher = translationPatch.Publisher;
				if (translationPatch.PagesCount != null) translation.PagesCount = translationPatch.PagesCount;
				if (translationPatch.FormatType != null) translation.FormatType = translationPatch.FormatType;
				if (translationPatch.CoverImage != null) translation.CoverImage = translationPatch.CoverImage;
				if (translationPatch.AmazonUrl != null) translation.AmazonUrl = translationPatch.AmazonUrl;
				if (translationPatch.Tags != null) translation.Tags = translationPatch.Tags; // ???

			}
		}
		public Book Post(Book book)
		{
			_db.Books.Add(book);

			return book;
		}
		public TranslatedBook Put(string id, Book updateBook)
		{
			_db.Entry(updateBook).State = EntityState.Modified;
			_db.Entry(updateBook.Translations.First()).State = EntityState.Modified;
			return new TranslatedBook(updateBook);
		}