public ActionResult Save(BookViewModel book, [Bind(Prefix = "Image")] HttpPostedFileBase image, [Bind(Prefix = "ImageChanged")] bool imageChanged) { if (ModelState.IsValid) { Book bookEntity = Mapper.Map <BookViewModel, Book>(book); byte[] imageBytes = null; if (imageChanged) { if (image != null) { imageBytes = Utils.Utils.StreamToArray(image.InputStream); } } else { imageBytes = booksRepository.GetImage(bookEntity.Id); } bookEntity.Image = imageBytes; if (bookEntity.Id > 0) { booksRepository.Update(bookEntity); } else { booksRepository.Create(bookEntity); } return(Json(Mapper.Map <Book, BookViewModel>(bookEntity))); } return(new JsonValidationError(ModelState)); }
public void AddBook() { var book = new Book(); book.Name = "First Book"; book.Price = 145.70M; _booksRepository.Create(book); _booksRepository.Save(); }
public async Task <bool> CreateAsync(Book book) { var dbBook = await _booksRepository.GetByTitleAsync(book.Title); if (dbBook == null) { _booksRepository.Create(book); return(true); } return(false); }
public bool Create(Book book) { var dbBook = _booksRepository.GetByTitle(book.Title); if (dbBook == null) { _booksRepository.Create(book); return(true); } return(false); }
public StatusModel Create(Book book) { var response = new StatusModel(); var dbBook = _booksRepository.GetByTitle(book.Title); if (dbBook == null) { _booksRepository.Create(book); response.Message = $"The book with title {book.Title} has been successfully created"; return(response); } else { response.Message = $"The book with title {book.Title} already exists."; response.IsSuccessfull = false; return(response); } }
public Book Create(Book item) { log.Info <BooksApiController>("Create Book:" + item.ToString()); booksRepository.Create(item); return(item); }
public ActionResult Create(BooksStaroseletsEV book) { repo.Create(book); return(RedirectToAction("ListOfBooks")); }
public void Create(BookDto bookDto) { var book = bookDto.ToBook(); booksRepository.Create(book); }
public Book Create(Book book) { return(_bookRepository.Create(book)); }