public IActionResult Post([FromBody] Library value) { if (value == null) { return(BadRequest()); } var createdLibrary = _libraryRepository.Add(value); return(CreatedAtRoute("GetLibrary", new { id = createdLibrary.LibraryId }, createdLibrary)); }
public async Task <IActionResult> Post(Book book) { await _libraryRepository.Add(book); if (book == null) { return(NotFound("No record with that ID")); } return(CreatedAtAction(nameof(Get), new { ID = book.ID }, book)); }
public async Task <IActionResult> CreateBook(ViewBookModel viewBook) { using (var ms = new MemoryStream()) { viewBook.BookFile.CopyTo(ms); var fileBytes = ms.ToArray(); viewBook.ByteBook = fileBytes; } var book = new Book() { Author = viewBook.Author, Title = viewBook.Title, ByteBook = viewBook.ByteBook }; var repoTag = await _repo.GetTag(3); //var newTag = new Tag() { TagName = "NovTag" }; var bookTag = new BookTags() { TagId = repoTag.Id, BookId = book.Id }; _repo.Add(bookTag); _repo.Add(book); if (await _repo.SaveAll()) { var url = "https://localhost:44307/api/books/"; return(Redirect(url + book.Id)); } return(Ok("Was not saved")); }
public IActionResult Create() { var austen = new Author { Name = "Jane Austen" }; var emma = new Book { Title = "Emma", Author = austen, Year = 1815 }; _repository.Add(emma); _repository.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public void Load(string sourcePath) { if (_libraryRepository.Exists(sourcePath)) { return; } var reader = _streamReaderProvider.Get(sourcePath); var jsonContents = reader.ReadToEnd(); reader.Close(); var deserializer = new JavaScriptSerializer(); var lib = deserializer.Deserialize <Library>(jsonContents); lib.Source = sourcePath; _libraryRepository.Add(lib); }
public async Task <IActionResult> Create(ViewBookModel viewBook) { var TagsForNewBoook = await _repo.TagsForNewBook(); using (var ms = new MemoryStream()) { viewBook.BookFile.CopyTo(ms); var fileBytes = ms.ToArray(); viewBook.ByteBook = fileBytes; } var newBook = new Book() { Id = GetHashCode(), Author = viewBook.Author, Title = viewBook.Title, ByteBook = viewBook.ByteBook, IsNew = viewBook.IsNew }; foreach (var tag in TagsForNewBoook) { tag.ForNewBook = false; var bookTag = new BookTags() { BookId = newBook.Id, TagId = tag.Id }; _repo.Add(bookTag); } _repo.Add(newBook); //_repo.SaveAll(); //var url = "https://localhost:44307/api/books/"; //return Redirect(url + newBook.Id); if (await _repo.SaveAll()) { var url = "https://localhost:44307/api/books/"; return(Redirect(url + newBook.Id)); } return(Ok("Was not saved")); //var path = "D:/Employee_Report - Copy.pdf"; //Book viewBook = new Book() //{ // Author = "Dimitar C.", // FilePathToBook = "D:/Employee_Report - Copy.pdf", // ByteBook = System.IO.File.ReadAllBytes(path), // Title = "Employee_Report - Copy" //}; // From File to Byte[] // return new EmptyResult(); //return Ok(); // return new HttpStatusCodeResult(204); }
public void AddLibrary(Library library) { libraryRepository.Add(library); }