public IActionResult Update(BookDetailModel asset, IFormFile ImageUrl) { string message = ""; var data = _assets.GetById(asset.AssetId); if (ImageUrl != null) { asset.ImageUrl = "/images/assets/" + ImageUrl.FileName; data.ImageUrl = asset.ImageUrl; var fileName = Path.Combine(he.WebRootPath + "/images/assets", Path.GetFileName(ImageUrl.FileName)); ImageUrl.CopyTo(new FileStream(fileName, FileMode.Create)); } if (ModelState.IsValid) { data.Title = asset.Title; data.Author = asset.AuthorOrDirector; data.DeweyIndex = asset.Dewey; data.NumberOfCopies = asset.NumberOfCopies; data.Year = asset.Year; data.Cost = asset.Cost; bool result = _assets.Update(data); if (result) { message += "Successfully"; } else { message += "Result return false"; } } //return Content(message); return(RedirectToAction("ListBook")); }
public IActionResult Detail([FromRoute] int id) { BookDetailModel book = new BookDetailModel(); book = LibraryBooks[id]; return(View(book)); }
public async Task <BaseResponse> CreateBook(BookDetailModel newBook) { var res = new BaseResponse(); if (await IsBookExisted(newBook)) { res.SetMessage("Buku sudah pernah dibuat", (int)MessageTypeEnum.Warning); res.SetFailedtatsus(); return(res); } try { this._DbMan.Books.Add(new SimpleLibraryDbContext.Entities.Book { BookAuthor = newBook.AuthorName, BookDescription = newBook.BookDescription, BookGenre = newBook.BookGenre, BookName = newBook.BookName, CreatedAt = DateTime.Now, CreateBy = "SYSTEM" }); await this._DbMan.SaveChangesAsync(); } catch (Exception ex) { //ex should be loggeg to logging services res.SetMessage(CommonMessage.CommonErrorMessage, (int)MessageTypeEnum.Exception); res.SetFailedtatsus(); return(res); } res.SetSuccessStatsus(); res.SetMessage("Buku berhasil dibuat", (int)MessageTypeEnum.Success); return(res); }
public async Task <IActionResult> Get(string id) { BookResponse book = await _bookService.GetBookDetailAsync(id); BookDetailModel bookDetailModel = new BookDetailModel().TransformToModel(book); return(Ok(bookDetailModel)); }
public async Task <IActionResult> EditBook(int id, [FromBody] BookDetailModel book) { var res = await _BookMan.UpdateBook(id, book); if (res.Status == false) { return(BadRequest(res)); } return(Ok(res)); }
public async Task <IActionResult> CreateBook([FromBody] BookDetailModel book) { var res = await _BookMan.CreateBook(book); if (res.Status == false) { return(BadRequest(res)); } return(Ok(res)); }
public IActionResult Index() { var model = new BookDetailModel(); model.Author("Deflo"); model.Title("Spannend"); model.ISBN(12); model.CreatedOn(09 / 12); return(View(model)); }
private async Task <bool> IsBookExisted(BookDetailModel book) { var existedBook = await this._DbMan.Books .Where(Q => Q.BookName == book.BookName && Q.BookGenre == book.BookGenre && Q.BookDescription == book.BookDescription && Q.BookAuthor == book.AuthorName) .FirstOrDefaultAsync(); if (existedBook != null) { return(true); } return(false); }
public IActionResult Index() { var model = new BookListViewModel(); BookDetailModel book = new BookDetailModel(); var i = 1; model.Books = new List <BookDetailModel>(); foreach (object librarybook in LibraryBooks) { book = LibraryBooks[i]; model.Books.Add(book); i++; } return(View(model)); }
public async Task <IActionResult> GetBookDetail(string bookId) { try { var id = ObjectId.Parse(bookId); var retval = await _bookRepo.GetOne(id, BookDetailModel.GetMap()) ?? throw new ArgumentException($"Invalid id {bookId}"); return(Ok(retval)); } catch (ArgumentException ex) { _log.LogWarning(ex, ex.Message); return(BadRequest(ex.Message)); } catch (Exception ex) { _log.LogError(ex, ex.Message); return(StatusCode(500, ex.Message)); } }
// Gets information from a specific book and returns it to the view public IActionResult Detail(int id) { var model = new BookDetailModel(); var book = _bookService.GetFromID(id); model.ID = id; model.Title = book.Title; model.ISBN = book.ISBN; model.Description = book.Description; model.AuthorName = book.Author.Name; model.BookCopies = _bookCopyService.GetAllBookCopiesFromBookID(id); model.AvailableBookCopies = _bookCopyService.GetAllAvailableBookCopiesFromBookID(id); return(View(model)); }
public IActionResult Index() { var assetModels = _bookService.GetAll(); var listingResult = assetModels .Select(a => new BookDetailListingModel { Id = a.Id, Title = a.Title, Author = "Raji", Whom = _bookService.GetWhom(a.Id) }).ToList(); var model = new BookDetailModel { Books = listingResult }; return(View(model)); }
public IActionResult EditBook(int id) { var asset = _assets.GetById(id); var model = new BookDetailModel { AssetId = id, Title = asset.Title, Year = asset.Year, Cost = asset.Cost, Status = asset.Status.Name, NumberOfCopies = asset.NumberOfCopies, ImageUrl = asset.ImageUrl, AuthorOrDirector = _assets.GetAuthorOrDirector(id), //Ham duoc viet cho lop Interface - Services Dewey = _assets.GetDeweyIndex(id), ISBN = _assets.GetIsbn(id) }; return(View(model)); }
public async Task <DataResponse <BookDetailModel> > UpdateBook(int id, BookDetailModel updatedBook) { var res = new DataResponse <BookDetailModel>(); res.Data = new BookDetailModel(); var book = await this._DbMan.Books.Where(Q => Q.BookId == id).FirstOrDefaultAsync(); if (book == null) { res.SetFailedtatsus(); res.SetMessage("Book not found", (int)MessageTypeEnum.Warning); return(res); } book.BookAuthor = updatedBook.AuthorName; book.BookDescription = updatedBook.BookDescription; book.BookGenre = updatedBook.BookGenre; book.BookName = updatedBook.BookName; book.UpdatedAt = DateTime.Now; book.UpdatedBy = "SYSTEM"; try { this._DbMan.Update(book); await this._DbMan.SaveChangesAsync(); } catch (Exception ex) { //ex should be loggeg to logging services res.SetMessage(CommonMessage.CommonErrorMessage, (int)MessageTypeEnum.Exception); res.SetFailedtatsus(); return(res); } res.Data = await this.GetPrivateBook(id); res.SetSuccessStatsus(); res.SetMessage("Buku berhasil diupdate", (int)MessageTypeEnum.Success); return(res); }
public BookDetailViewModel() { BookReviews = new List <Review>(); BookImages = new List <BookImage>(); Book = new BookDetailModel(); }