public async Task <IActionResult> Edit(int id, [Bind("FilmId,Title,Description,ReleaseYear,LanguageId,OriginalLanguageId,RentalDuration,RentalRate,Length,ReplacementCost,Rating,SpecialFeatures,LastUpdate")] Film film) { if (id != film.FilmId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(film); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FilmExists(film.FilmId)) { return(NotFound()); } else { throw; } } 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> Edit(int id, [Bind("CustomerId,StoreId,FirstName,LastName,Email,AddressId,Active,CreateDate,LastUpdate")] Customer customer) { if (id != customer.CustomerId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.CustomerId)) { return(NotFound()); } else { throw; } } 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> Edit(int id, [Bind("AddressId,Address1,Address2,District,CityId,PostalCode,Phone,LastUpdate")] Address address) { if (id != address.AddressId) { return NotFound(); } if (ModelState.IsValid) { try { _context.Update(address); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(address.AddressId)) { return NotFound(); } else { throw; } } return RedirectToAction(nameof(Index)); } ViewData["CityId"] = new SelectList(_context.City, "CityId", "City1", address.CityId); return View(address); }
public async Task <IActionResult> Edit(int id, [Bind("ActorId,FirstName,LastName,LastUpdate")] Actor actor) { if (id != actor.ActorId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(actor); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActorExists(actor.ActorId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(actor)); }
public async Task <IActionResult> Edit(int id, [Bind("RentalId,RentalDate,InventoryId,CustomerId,ReturnDate,StaffId,LastUpdate")] Rental rental) { if (id != rental.RentalId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(rental); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentalExists(rental.RentalId)) { return(NotFound()); } else { throw; } } 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)); }
private void updateCityRecord() { using (var dbContext = new sakilaContext()) { var city = dbContext.City.SingleOrDefault(x => x.CityId == 1001); if (city != null) { city.Name = "Alleppy"; dbContext.Update(city); dbContext.SaveChanges(); } } }
static void Main(string[] args) { // get record var dbContext = new sakilaContext(); var records = dbContext.Film.Include(f => f.FilmActor).ThenInclude(r => r.Actor).ToList(); foreach (var record in records) { System.Console.WriteLine($"Film: {record.Title}"); var counter = 1; foreach (var fa in record.FilmActor) { System.Console.WriteLine($"\tActor {counter++}: {fa.Actor.FirstName} {fa.Actor.LastName}"); } } // add record // var city = new City() { CityId = 1001, Name = "Redmond", CountryId = 103 }; // dbContext.Add(city); // dbContext.SaveChanges(); // update record var uTarget = dbContext.City.SingleOrDefault(c => c.CityId == 1001); if (uTarget != null) { uTarget.Name = "Kirkland"; dbContext.Update(uTarget); dbContext.SaveChanges(); } var dTarget = dbContext.City.SingleOrDefault(c => c.CityId == 1001); if (dTarget != null) { dbContext.Remove(dTarget); dbContext.SaveChanges(); } }