public BookViewModel GetBookList() { BookViewModel viewModel = new Models.BookViewModel(); try { List <BookModel> bookList = new List <BookModel>(); IEnumerable <string> fileList = fileReader.GetAllFiles(); foreach (var file in fileList) { string fileFormat = fileReader.GetFileFormat(file).ToUpper(); context = factory.CreateContext(fileFormat); if (context != null) { string[] lines = fileReader.ReadTheFile(file); bookList.AddRange(context.ReadBook(lines)); } } viewModel.Books = bookList; viewModel.Errors = ErrorHandler.ErrorList; } catch (Exception e) { ErrorHandler.AddError(ErrorTypes.ER0, e); viewModel.Errors = ErrorHandler.ErrorList; } return(viewModel); }
public ActionResult CreateBook(Models.BookViewModel book) { ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = serviceObj.PostResponse("api/Book/AddBook", book); response.EnsureSuccessStatusCode(); return(RedirectToAction("GetAllBooks")); }
/// <summary> /// Get detailed information about the book. /// </summary> /// <param name="id">Book ID </param> public ActionResult Details(int id) { ServiceRepository serviceObj = new ServiceRepository(); HttpResponseMessage response = serviceObj.GetResponse("api/Book/GetBook?id=" + id.ToString()); response.EnsureSuccessStatusCode(); Models.BookViewModel products = response.Content.ReadAsAsync <Models.BookViewModel>().Result; ViewBag.Title = "All Book"; return(View(products)); }