public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { int id = await _bookrepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction("AddNewBook", new { isSuccess = true, bookId = id })); } } ViewBag.Language = new SelectList(await _languagerepository.GetLanguage(), "Id", "Name"); //ViewBag.Language = new SelectList(new List<string>() { "Hindi", "English", "Gujarati" }); //var group1 = new SelectListGroup() { Name = "Group1" }; //var group2 = new SelectListGroup() { Name = "Group2", Disabled = true }; //var group3 = new SelectListGroup() { Name = "Group3" }; //ViewBag.Language = new List<SelectListItem>() //{ // new SelectListItem(){Text="Hindi",Value="1", Group=group1}, // new SelectListItem(){Text="English",Value="2",Group=group1}, // new SelectListItem(){Text="Hindi",Value="3", Group=group2}, // new SelectListItem(){Text="Tamil",Value="4",Group=group2}, // new SelectListItem(){Text="Dutch",Value="5",Group=group3}, // new SelectListItem(){Text="Franch",Value="6",Group=group3}, // new SelectListItem(){Text="Urdu",Value="7",Group=group3} //}; //ModelState.AddModelError("", "This is my custom error message"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { if (bookModel.CoverPhoto != null) { string folder = "books/cover/"; bookModel.CoverImageUrl = await UploadImage(folder, bookModel.CoverPhoto); } if (bookModel.GalleryFiles != null) { string folder = "books/gallery/"; bookModel.Gallery = new List <GalleryModel>(); foreach (var file in bookModel.GalleryFiles) { var gallery = new GalleryModel() { Name = file.FileName, URL = await UploadImage(folder, file) }; bookModel.Gallery.Add(gallery); } } if (bookModel.BookPdf != null) { string folder = "books/pdf/"; bookModel.BookPdfUrl = await UploadImage(folder, bookModel.BookPdf); } int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } ViewBag.Language = new SelectList(await _languageRepository.GetLanguages(), "Id", "Name"); //var group1 = new SelectListGroup() { Name = "Group 1" }; //var group2 = new SelectListGroup() { Name = "Group 2", Disabled = true }; //ViewBag.Language = new List<SelectListItem> { // new SelectListItem() { Text="English", Value="1" ,Group = group1}, // new SelectListItem() { Text="English(U.K)" , Value="2" ,Group = group1}, // new SelectListItem() { Text="Turkish" , Value="3", Disabled = true ,Group = group2} //}; ModelState.AddModelError("", "This is my error message"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { int Id = await _bookRepository.AddNewBook(bookModel); if (Id > 0) { return(RedirectToAction("AddNewBook", new { isSuccess = true, BookId = Id }));; } return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { //It will return to the AddNew Book Page so it will make the field Empty return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } return(View()); }
public IActionResult AddNewBook(BookModel bookModel) { int id = _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction("AddNewBook", new { isSuccess = true, bookId = id })); } return(View()); }
public IActionResult AddNewBook(Book book) { int id = _bookRepository.AddNewBook(book); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } return(View()); }
public async Task <IActionResult> AddBook(BookModel bookModel) { if (ModelState.IsValid) { await bookRepository.AddNewBook(bookModel); return(RedirectToAction("AddBook", "Book", new { Msg = true })); } ModelState.AddModelError("", "This is custom Error"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bm) { if (ModelState.IsValid) { int id = await br.AddNewBook(bm); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { issuccess = true, bookid = id })); } } return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } ViewBag.Laguage = new SelectList(await _languageRepository.GetLanguages(), "Id", "Name"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { Title = "Add Book"; if (ModelState.IsValid) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction("AddNewBook", new { isSuccess = true })); } } return(View()); }
public async Task <IActionResult> AddNewBook(Book model) { if (ModelState.IsValid) { var id = await _bookRepo.AddNewBook(model); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { IsSuccess = true, bookId = id })); } } ModelState.AddModelError("", "This is First custom model error"); ModelState.AddModelError("", "This is Second Custom Model Error"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { if (bookModel.CoverPhoto != null) { string folder = "books/cover/"; bookModel.CoverImageUrl = await UploadImage(folder, bookModel.CoverPhoto); } if (bookModel.GalleryPhotos != null) { string folder = "books/gallery/"; bookModel.Gallery = new List <GalleryModel>(); foreach (var file in bookModel.GalleryPhotos) { var gallery = new GalleryModel() { Name = file.FileName, Url = await UploadImage(folder, file) }; bookModel.Gallery.Add(gallery); } } if (bookModel.BookPdf != null) { string folder = "books/pdf/"; bookModel.BookPdfUrl = await UploadImage(folder, bookModel.BookPdf); } int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } ViewBag.languages = new SelectList(await _languageRepository.GetLanguages(), "Id", "Name"); ViewBag.isSuccess = false; ViewBag.bookId = 0; return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } //ViewBag.IsSuccess = false; //ViewBag.BookId = 0; return(View()); }
public async Task <IActionResult> AddNewBook(BookModel book) { if (ModelState.IsValid) { int id = await bookRepository.AddNewBook(book); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } ModelState.AddModelError("", "This is my costum error message"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel book) { if (book.CoverPhoto != null) { string folder = "Books/Cover/"; book.CoverImageUrl = await UploadFile(folder, book.CoverPhoto); } if (book.GalleryImages != null) { string folder = "Books/GalleryImgs/"; book.GalleryImgs = new List <GalleryModel>(); foreach (var image in book.GalleryImages) { var gallery = new GalleryModel() { Name = image.Name, URL = await UploadFile(folder, image) }; book.GalleryImgs.Add(gallery); } //book.CoverImageUrl = await UploadImage(folder, book.CoverPhoto); } if (book.PDF != null) { string folder = "Books/PDF/"; book.PDFUrl = await UploadFile(folder, book.PDF); } if (ModelState.IsValid) { var id = await _bookRepository.AddNewBook(book); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } ViewBag.languageList = new SelectList(await _languageRepository.GetAllLanguages(), "Id", "Name"); //ViewBag.languageList = GetLanguages(); ViewBag.isSuccess = false; ViewBag.BookId = 0; ModelState.AddModelError("", "Please check if all the required entries are provided"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookmodel) //Action method ;when we submit all the book details..it will be hitting to bookmodel (view) { if (ModelState.IsValid) { var id = await _bookRepository.AddNewBook(bookmodel); //since return type is id, if (id > 0) //after submitting ..clear the textboxes { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } ModelState.AddModelError("", "custom error messages"); ViewBag.language = new SelectList(await _languageRepo.GetLanguage(), "Id", "Name"); /*var list = new List<String>() { "HIndi", "English", "Assamese" };*//*selected language is sending to server to store in database*/ return(View()); }
public async Task <IActionResult> UploadBook(BookModels book) { if (ModelState.IsValid) { //check if FormFile is not null if (book.CoverPhotoFile != null) { //function call to save image to mention file //pass book path with filename to book model book.BookCoverPhoto = await SaveImage("Images/Books/CoverPhoto/", book.CoverPhotoFile);; } if (book.BookGalleries != null) { book.BookGallery = new List <BookGalleryModels>(); foreach (IFormFile file in book.BookGalleries) { BookGalleryModels Gallery = new BookGalleryModels() { PictureName = file.FileName, URL = await SaveImage("Images/Books/GalleryPhoto", file) }; book.BookGallery.Add(Gallery); } } if (book.BookPDF != null) { string BookFile = "BookPDF/" + Guid.NewGuid().ToString() + "_" + book.BookPDF.FileName; //create a url to save the book in the server string serverFolder = Path.Combine(webHostEnvironment.WebRootPath, BookFile); await book.BookPDF.CopyToAsync(new FileStream(serverFolder, FileMode.Create)); book.BookURL = "/" + BookFile; } long id = await bookRepository.AddNewBook(book); if (id > 0) { return(RedirectToAction(nameof(UploadBook), new { isSuccess = true, BookID = (int)id })); } } //function call to get languages from database ViewBag.Languages = await LanguageDropDown(); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } // == Creating a list and pass it from controller //ViewBag.language = new List<string>() { "Urdu", "Punjabi", "English" }; // == Creating Select List and pass it direct from controller ViewBag.language = new SelectList(new List <string>() { "Urdu", "Punjabi", "English" }); //== Creating Groups for SlectListItems //var group1 = new SelectListGroup() { Name = "Group1" }; //var group2 = new SelectListGroup() { Name = "Group2" }; //var group3 = new SelectListGroup() { Name = "Group3" }; // == Creating SelectListGroup and pass it from controller //ViewBag.Language = new List<SelectListItem>() //{ // new SelectListItem(){ Text = "hindi", Value = "1" , Group = group1}, // new SelectListItem(){ Text = "English", Value = "2" , Group = group1}, // new SelectListItem(){ Text = "Urdu", Value = "3" , Group = group2}, // new SelectListItem(){ Text = "Tamil", Value = "4" , Group = group2}, // new SelectListItem(){ Text = "Punjabi", Value = "5" , Group = group3}, // new SelectListItem(){ Text = "Chinese", Value = "6" , Group = group3}, //}; //ModelState.AddModelError("", "This is the custom error message"); //ModelState.AddModelError("", "This is the second custom error message"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { //upload a single cover photo if (bookModel.CoverPhotos != null) { string folder = "images/Books/cover/"; bookModel.CoverImageUrl = await UploadImage(folder, bookModel.CoverPhotos); } //upload gallery images if (bookModel.GalleryImages != null) { string folder = "images/Books/gallery/"; bookModel.Gallery = new List <GalleryModel>(); foreach (var file in bookModel.GalleryImages) { var gallery = new GalleryModel() { Name = file.Name, ImageUrl = await UploadImage(folder, file) }; bookModel.Gallery.Add(gallery); } } int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } else { ModelState.AddModelError("", "Could not save book to the store!"); } } ViewBag.CategoryList = new SelectList(GetCategories(), "Id", "Text"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } ViewBag.Language = new SelectList(new List <string>() { "Bahasa Indonesia", "English", "한국어", "日本語" }); ModelState.AddModelError("", "Some fields are invalid"); return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { if (bookModel.CoverPhoto != null) { string folder = "book/cover/"; folder += Guid.NewGuid() + bookModel.CoverPhoto.FileName; bookModel.CoverPhotoUrl = "/" + folder; string serverfolder = Path.Combine(_webHostEnvironment.WebRootPath, folder); await bookModel.CoverPhoto.CopyToAsync(new FileStream(serverfolder, FileMode.Create)); } int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } //ViewBag.IsSuccess = false; //ViewBag.BookId = 0; return(View()); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { ViewBag.Language = new SelectList(GetLanguage(), "Id", "Text"); if (!ModelState.IsValid) { ViewBag.IsSuccess = false; ViewBag.BookId = 0; ModelState.AddModelError("", "This is first custom error for demo."); ModelState.AddModelError("", "This is second custom error for demo."); return(View()); } if (ModelState.IsValid) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } return(View()); }
public async Task <IActionResult> AddNewBook(BookModel NewBook) { if (ModelState.IsValid) { int value = await _newBookRepository.AddNewBook(NewBook); if (value > 0) { return(RedirectToAction("AddNewBook", new { check = true, bookId = value })); } } //ViewBag.DDBL = new SelectList(_newBookRepository.bookLangPublic(), "bookLanguageId", "bookLanguageName"); //ViewBag.DDBL = _newBookRepository.bookLangPublic().Select(a => new SelectListItem() //{ // Text = a.bookLanguageName, // Value = a.bookLanguageId.ToString() //}).ToList(); //var group1 = new SelectListGroup() { Name = "group1" }; //var group2 = new SelectListGroup() { Name = "group2",Disabled=true }; //var group3 = new SelectListGroup() { Name = "group3" }; //ViewBag.DDBL = new List<SelectListItem>() { // new SelectListItem(){Text="arabic1",Value="1",Group=group1}, // new SelectListItem(){Text="arabic12",Value="2",Group=group1 }, // new SelectListItem(){Text="arabic13",Value="3" ,Group=group2}, // new SelectListItem(){Text="arabic14",Value="4",Group=group2}, // new SelectListItem(){Text="arabic15",Value="5",Group=group3 }, // new SelectListItem(){Text="arabic16",Value="6" ,Group=group3} //}; ViewBag.DDBL = new SelectList(await _LanguageRepository.GetALlBooksLanguages(), "LanguageId", "LanguageName"); ModelState.AddModelError("", "Please fill the Errors fields"); return(View(NewBook)); }
public async Task <IActionResult> AddNewBook(BookModel bookModel) { if (ModelState.IsValid) { int id = await _bookRepository.AddNewBook(bookModel); if (id > 0) { return(RedirectToAction(nameof(AddNewBook), new { isSuccess = true, bookId = id })); } } ViewBag.Language = new List <string>() { "English", "Hindi", "Ducth" }; ViewBag.Lang = new SelectList(GetLanguages(), "Id", "Text"); ViewBag.IsSuccess = false; ViewBag.BookId = 0; ModelState.AddModelError("", "There is an error"); ModelState.AddModelError("", "There is an error second One"); return(View()); }