public ActionResult Create(Book objBook) { int stateid = 1; if (TempData["StateId"] != null) { stateid = (int)TempData["StateId"]; } if (!ModelState.IsValid) { objBook.States = GetAllStates(); objBook.Cities = GetAllCities().Where(c => c.StateId == stateid).ToList(); BookViewModel bookViewModel = objBook; return(View("Create", bookViewModel)); } //var selectedItem = objBook.Cities.Find(p => p.CityName == objBook.CityID.ToString()); objBook.State = GetAllStates().Where(m => m.Id == stateid).FirstOrDefault().StateName; var cModel = GetAllCities().Where(m => m.StateId == stateid); SelectList obgcity = new SelectList(cModel, "Id", "CityName", 0); objBook.PublishedDateTime = DateTime.Today; //var stateName = TempData["selectedStateName"]; var model = BookDB.AddBook(objBook); var bookVModel = CreateListBookViewmodel(model); return(View("Index", bookVModel)); }
public IActionResult Create(Book book) { if (ModelState.IsValid) { _db.AddBook(book); TempData["Message"] = "You have added a new book"; return(RedirectToAction("Index")); } return(View()); }
public ActionResult Post([FromBody] RequestBook book) { try { bookData.AddBook(book); return(Created($"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}/{book.Id}", book)); } catch (Exception ex) { return(BadRequest(ex.Message.Contains("inner") ? ex.InnerException.Message : ex.Message)); } }
public IActionResult Create(BookEditModel bookEditModel) { if (ModelState.IsValid) { var newBook = new BookRepo(); newBook.Name = bookEditModel.Name; newBook.Type = bookEditModel.Type; newBook = _bookData.AddBook(newBook); return(RedirectToAction(nameof(Info), new { id = newBook.BookId })); } else { return(View()); } }
public IActionResult OnPost() { if (!ModelState.IsValid) { Genres = htmlHelper.GetEnumSelectList <BookGenre>(); return(Page()); } if (Book.BookID > 0) { bookData.UpdateBook(Book); } else { bookData.AddBook(Book); } bookData.Commit(); return(RedirectToPage("./Detail", new { bookId = Book.BookID })); }
public Result <BookStore> AddBook(BookStore book) { var result = new Result <BookStore>(); try { ruleContext.RuleValidation(book); bookData.AddBook(book); result.Successful = true; result.Message = $"the store has {book.Quantity} units of a book titled {book.Book.Title}"; result.Content = book; } catch (Exception ex) { result.Successful = false; result.Message = ex.Message; } return(result); }
public void AddBook(BookModel model) { _data.AddBook(model.Title, model.Description, model.AuthorFirstName, model.AuthorLastName, model.Publisher, model.ReleaseDate, model.Quantity, model.AvailableQuantity); }