public ActionResult Create(IFormCollection collection) { var newBook = new Domain.Models.Book(); if (ModelState.IsValid) { newBook.Title = collection["Title"]; newBook.AuthorFirstName = collection["AuthorFirstName"]; newBook.AuthorLastName = collection["AuthorLastName"]; newBook.Imagelink = collection["ImageLink"]; newBook.ISBN = collection["ISBN"]; newBook.Price = decimal.Parse(collection["Price"]); newBook.Genre = new Domain.Models.Genre { ID = Int32.Parse(collection["GenreList"]) }; } try { _bookrepository.AddBook(newBook); return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction(nameof(Create), newBook)); } }
public static Book ToEntity(this Domain.Models.Book book, bool isActive = true) => new Book { Id = book.Id, CreateDate = book.CreateDate, UpdateDate = book.UpdateDate, IsActive = isActive, Name = book.Name, NumberOfPages = book.NumberOfPages, DateOfPublication = book.DateOfPublication };
public async Task <bool> Handle(AddBookCommand request, CancellationToken cancellationToken) { Domain.Models.Book book = new Domain.Models.Book(); book.Name = request.Name; book.Price = request.Price; book.Author = request.Author; book.PubDate = request.PubDate; book.Status = BorrowStatus.Borrowing; _bookRepository.Insert(book); return(await _unitOfWork.SaveChangesAsync() > 0); }
/// <summary> /// The purpose of this method to take a model book and turn it into a db book /// </summary> /// <param name="book"></param> /// <returns></returns> public static Entities.BookEntity Map(Domain.Models.Book book) { return(new Entities.BookEntity { Isbn = book.ISBN, AuthorFirstName = book.AuthorFirstName, AuthorLastName = book.AuthorLastName, Name = book.Title, Price = book.Price, GenreId = book.Genre.ID, ImageLink = book.Imagelink }); }