public ActionResult Add(Actor actor) { //dohvaćanje idućeg slobodnog ID-a, može li bolje/izravnije? actor.ActorId = (ushort)((_context.Actor.Select(x => x.ActorId).Max()) + 1); _context.Add(actor); _context.SaveChanges(); return(RedirectToAction("Index")); }
public async Task<IActionResult> Create([Bind("AddressId,Address1,Address2,District,CityId,PostalCode,Phone,LastUpdate")] Address address) { if (ModelState.IsValid) { _context.Add(address); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } ViewData["CityId"] = new SelectList(_context.City, "CityId", "City1", address.CityId); return View(address); }
public async Task <IActionResult> Create([Bind("ActorId,FirstName,LastName,LastUpdate")] Actor actor) { if (ModelState.IsValid) { _context.Add(actor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(actor)); }
private void addCity() { using (var dbContext = new sakilaContext()) { var city = new City() { CityId = 1001, Name = "Alappuzha", CountryId = 103 }; dbContext.Add(city); dbContext.SaveChanges(); } }
public async Task <IActionResult> Create([Bind("CustomerId,StoreId,FirstName,LastName,Email,AddressId,Active,CreateDate,LastUpdate")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AddressId"] = new SelectList(_context.Address, "AddressId", "Address1", customer.AddressId); ViewData["StoreId"] = new SelectList(_context.Store, "StoreId", "StoreId", customer.StoreId); return(View(customer)); }
public async Task <IActionResult> Create([Bind("FilmId,Title,Description,ReleaseYear,LanguageId,OriginalLanguageId,RentalDuration,RentalRate,Length,ReplacementCost,Rating,SpecialFeatures,LastUpdate")] Film film) { if (ModelState.IsValid) { _context.Add(film); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LanguageId"] = new SelectList(_context.Language, "LanguageId", "Name", film.LanguageId); ViewData["OriginalLanguageId"] = new SelectList(_context.Language, "LanguageId", "Name", film.OriginalLanguageId); return(View(film)); }
public async Task <IActionResult> Create([Bind("RentalId,RentalDate,InventoryId,CustomerId,ReturnDate,StaffId,LastUpdate")] Rental rental) { if (ModelState.IsValid) { _context.Add(rental); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "Active", rental.CustomerId); ViewData["InventoryId"] = new SelectList(_context.Inventory, "InventoryId", "InventoryId", rental.InventoryId); ViewData["StaffId"] = new SelectList(_context.Staff, "StaffId", "FirstName", rental.StaffId); return(View(rental)); }