public ActionResult Create(BookCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateBookService(); if (service.CreateBook(model)) { TempData["SaveResult"] = "Your book was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your book could not be created."); return(View(model)); }
public ActionResult Create(BookCreate model) { if (!ModelState.IsValid) { return(View(model)); } BookService service = CreateBookService(); if (service.CreateBook(model)) { TempData["SaveResult"] = "Your book was successally added to the database."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "An error was encountered. Your book could not be added."); return(View(model)); }
public bool CreateBook(BookCreate model) { var entity = new Book() { OwnerId = _userId, Title = model.Title, AuthorName = model.Author, Description = model.Description, AvgBookRating = model.Rating, BookGenre = model.BookGenre, }; using (var ctx = new ApplicationDbContext()) { ctx.Books.Add(entity); return(ctx.SaveChanges() == 1); } }
// Post -- Create public bool CreateBook(BookCreate book) { var entity = new Book() { ISBN = book.ISBN, BookTitle = book.BookTitle, AuthorFirstName = book.AuthorFirstName, AuthorLastName = book.AuthorLastName, GenreOfBook = book.GenreOfBook, Description = book.Description, }; using (var ctx = new ApplicationDbContext()) { ctx.Books.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateBook(BookCreate model) { var entity = new Book() { Name = model.Name, OwnerId = _userId, Author = model.Author, Genre = model.Genre, PublishedDate = model.PublishedDate, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Books.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateBook(BookCreate model) { var entity = new Book() { UserId = _userID, CrimeID = model.CrimeID, Crime = model.Crime, Title = model.Title, Description = model.Description, BookAuthor = model.BookAuthor, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Books.Add(entity); return(ctx.SaveChanges() == 1); } }
private BookCreate BuidBookCreate(Guid?categoryId = null, Guid?editorId = null, Guid?firmId = null) { var categories = new SelectList(CategoryRepository.GetAll(), "Id", "Title", categoryId); var allEditors = EditorRepository.GetAll(); allEditors.Insert(0, null); var editors = new SelectList(allEditors, "Id", "Title", editorId); var allFirms = FirmRepository.GetAll(); allFirms.Insert(0, null); var firms = new SelectList(allFirms, "Id", "Title", firmId); var bookCreate = new BookCreate { Categories = categories, Editors = editors, Firms = firms }; return(bookCreate); }
public bool CreateBook(BookCreate model) { var entity = new Book() { OwnerID = _userID, Title = model.Title, Author = model.Author, Description = model.Description, YearPublished = model.YearPublished, DateRead = model.DateRead, IsRecommended = model.IsRecommended, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Books.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateBook(BookCreate model) { var entity = new Book() { CreatorId = _creatorId, BookName = model.BookName, Genre = model.Genre, Rating = model.Rating, Price = model.Price, PageCount = model.PageCount, Description = model.Description }; //entity.Themes.Add() -- future development using (var ctx = new ApplicationDbContext()) { ctx.Books.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateBook(BookCreate bookToCreate) { var entity = new Book() { Title = bookToCreate.Title, SeriesTitle = bookToCreate.SeriesTitle, AuthorId = bookToCreate.AuthorId, Isbn = bookToCreate.Isbn, Rating = bookToCreate.Rating, Genre = bookToCreate.Genre, Language = bookToCreate.Language, Publisher = bookToCreate.Publisher, IsEbook = bookToCreate.IsEbook }; using (var ctx = new ApplicationDbContext()) { ctx.Books.Add(entity); return(ctx.SaveChanges() == 1); } }
public async Task <IActionResult> Create(BookCreate bookToAdd) { if (!ModelState.IsValid) { return(View("New", bookToAdd)); } else { var book = new Book { Title = bookToAdd.Title, Author = bookToAdd.Author, InInventory = true, NumberOfPages = bookToAdd.NumberOfPages }; _dataContext.Books.Add(book); await _dataContext.SaveChangesAsync(); ViewData["flash"] = $"Book {book.Title} add as {book.Id}"; return(View("New", new BookCreate()));//PRG post redirect get } }
public int Create(BookCreate bookCreate) { int rowAffected = 0; using (IDbConnection con = new SqlConnection(strConnectionString)) { if (con.State == ConnectionState.Closed) { con.Open(); DynamicParameters parameters = new DynamicParameters(); parameters.Add("@Avatar", bookCreate.Avatar); parameters.Add("@Name", bookCreate.Name); parameters.Add("@Author", bookCreate.Author); parameters.Add("@Description", bookCreate.Description); parameters.Add("@Year", bookCreate.Year); parameters.Add("@Number", bookCreate.Number); parameters.Add("@CateloryID", bookCreate.IDCatelory); rowAffected = con.Execute("Book_Create", parameters, commandType: CommandType.StoredProcedure); } return(rowAffected); } }
public async Task <IActionResult> Create(BookCreate bookToAdd) { if (!ModelState.IsValid) { return(View("New", bookToAdd)); } else { // add it to the database and stuff. var book = new Book { Title = bookToAdd.Title, Author = bookToAdd.Author, InInventory = true, NumberOfPages = bookToAdd.NumberOfPages }; _dataContext.Books.Add(book); await _dataContext.SaveChangesAsync(); TempData["flash"] = $"Book {book.Title} add as {book.Id}"; return(RedirectToAction("New")); // PRG: Post Redirect Get } }
public bool CreateBook(BookCreate model) { var entity = new Book() { OwnerId = _userId, BookId = model.BookId, TypeOfBook = model.TypeOfBook, Title = model.Title, Author = model.Author, IsFiction = model.IsFiction, IsNewRelease = model.IsNewRelease, IsBestSeller = model.IsBestSeller, Price = model.Price, Inventory = model.Inventory, Description = model.Description, }; using (var ctx = new ApplicationDbContext()) { ctx.Book.Add(entity); return(ctx.SaveChanges() == 1); } }
public IHttpActionResult PostBook(BookCreate model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!Book.ValidGenres.Select(g => g.ToLower()).ToList().Contains(model.Genre.ToLower())) { string message = "Genre must be one of the following: "; foreach (string genre in Book.ValidGenres) { message += $"{genre}, "; } return(BadRequest(message)); } BookService service = CreateBookService(); if (!service.CreateBook(model)) { return(InternalServerError()); } return(Ok()); }
public IHttpActionResult Post(BookCreate book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateBookService(); if (!service.CreateBook(book)) { return(InternalServerError()); } return(Ok(book)); //return CreatedAtRoute("DefaultApi", new { name = book.Name }, book); //var bookCreate = new BookCreate() //{ // Name = book.Name, // Author = book.Author, // Genre = book.Genre //}; //return CreatedAtRoute("DefaultApi", new { name = book.Name }, bookCreate); }
protected void SaveCreate_Click(object sender, EventArgs e) { var title = (BookCreate.FindControl("BookTitle") as TextBox).Text; var authors = (BookCreate.FindControl("BookAuthors") as TextBox).Text; var ISBN = (BookCreate.FindControl("BookIsbn") as TextBox).Text; var site = (BookCreate.FindControl("BookSite") as TextBox).Text; var description = (BookCreate.FindControl("BookDescription") as TextBox).Text; var categoryId = int.Parse((BookCreate.FindControl("BookCategory") as DropDownList).SelectedValue); if (string.IsNullOrEmpty(title)) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title cannot be empty"); return; } else if (title.Length < 5 || title.Length > 50) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title must be between 5 and 50 symbols"); return; } else if (string.IsNullOrEmpty(authors)) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors cannot be empty"); return; } else if (authors.Length < 5 || authors.Length > 50) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors must be between 5 and 50 symbols"); return; } else if (ISBN.Length > 50) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("ISBN must be less than 50 symbols"); return; } else if (site.Length > 50) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("ISBN must be less than 50 symbols"); return; } else if (description.Length > 2000) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Description must be less than 2000 symbols"); return; } else if (categoryId == -1) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors cannot be empty"); return; } LibrarySystemDbContext context = new LibrarySystemDbContext(); context.Books.Add(new Book { Title = title, Authors = authors, ISBN = ISBN, WebSite = site, Description = description, CategoryId = categoryId }); context.SaveChanges(); BookCreate.DataSource = null; BookCreate.DataBind(); BooksGrid.DataBind(); }
protected void CancelCreate_Click(object sender, EventArgs e) { BookCreate.DataSource = null; BookCreate.DataBind(); }
public void Create([FromBody] BookCreate bookCreate) => bookBusiness.Create(bookCreate);
public ApiResponse Store(BookCreate bookCreate) { this.bookApplication.CreateFromAPI(bookCreate); return(new ApiResponseData(HttpStatusCode.OK, null)); }