public async Task <IActionResult> Create([Bind("GenreId,GenreName")] Genre genre) { if (ModelState.IsValid) { _context.Add(genre); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public async Task <IActionResult> Create([Bind("BranchId,BranchName,City,Address,Latitude,Longitude,PhoneNumber")] Branch branch) { if (ModelState.IsValid) { _context.Add(branch); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(branch)); }
public async Task <IActionResult> Create(IFormFile file, [Bind("BookId,BookName,Author,Publication,Price,Summary,PictureName,GenreId")] Book book) { if (ModelState.IsValid) { if (file == null) { ModelState.AddModelError("", "You must enter book picture"); } else if (GetAllBooks.Where(b => b.BookName == book.BookName).Count() == 0) { // get the image name and save the path to the saved pictures var filePath = _staticImagesRoute + file.FileName; // save the image name to the pictureName property so we get it later for the view book.PictureName = "/img/" + file.FileName; // save the picture to the static path using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); } // save book _context.Add(book); await _context.SaveChangesAsync(); FacebookConnection.PostMessage(book); return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError("", "The book already exist"); } } ViewData["GenreID"] = new SelectList(_context.Genres, "GenreId", "GenreName", book.GenreId); return(View(book)); }