public async Task <IActionResult> CreateBook(BookMaterialVM bookMaterialVM) { if (!ModelState.IsValid && await materialService.UniqueMaterialName(bookMaterialVM.Name)) { return(View("CreateBook", bookMaterialVM)); } var mappedBook = mapper.Map <BookMaterialVM, BookMaterial>(bookMaterialVM); await bookMaterialService.AddBookMaterial(mappedBook); return(RedirectToAction("MaterialList", "Material")); }
public BookMaterialVM BookFullData() { BookMaterialVM bookMaterialVM = new BookMaterialVM(); Console.WriteLine("Enter book name"); bookMaterialVM.Name = Console.ReadLine(); Console.WriteLine("Enter book author"); bookMaterialVM.Author = Console.ReadLine(); Console.WriteLine("Enter count of pages"); Int32.TryParse(Console.ReadLine(), out int countOfPages); bookMaterialVM.Pages = countOfPages; Console.WriteLine("Enter year of publish"); Int32.TryParse(Console.ReadLine(), out int yearOfPublish); bookMaterialVM.YearOfPublish = yearOfPublish; Console.WriteLine("Chose book format\n1 - Large\n2 - Medium\n3 - Small"); bookMaterialVM.Format = (Console.ReadLine()) switch { "1" => BookFormatVM.Large, "2" => BookFormatVM.Medium, "3" => BookFormatVM.Small, _ => BookFormatVM.Medium, }; return(bookMaterialVM); }