public ActionResult Create([Bind(Include = "MembershipTypeId,Name,SignUpFee,DurationInMonths,DiscountRate")] MembershipType membershipType) { if (ModelState.IsValid) { db.MembershipTypes.Add(membershipType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(membershipType)); }
public ActionResult Create([Bind(Include = "Id,Nome,IsSubscribedToNewsletter, DateOfBirth, MembershipTypeId")] Cliente cliente) { if (ModelState.IsValid) { db.Clientes.Add(cliente); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MembershipTypeId = new SelectList(db.MembershipTypes, "MembershipTypeId", "MembershipTypeId", cliente.MembershipTypeId); return(View(cliente)); }
public static bool RegisterNewMovie(Movie newMovie) { try { _context.Movies.Add(newMovie); _context.Database.Log = Console.WriteLine; _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult Save(Movie movie) { if (!ModelState.IsValid) { var viewModel = new MovieViewModel() { Movie = movie, Genre = _context.Genres.ToList() }; return(View("MovieForm", viewModel)); } movie.DateAdded = DateTime.Now; if (movie.Id == 0) { _context.Movies.Add(movie); } else { var movieInDb = _context.Movies.SingleOrDefault(m => m.Id == movie.Id); movieInDb.Name = movie.Name; movieInDb.GenreId = movie.GenreId; movieInDb.ReleaseDate = movie.ReleaseDate; movieInDb.NumberInStock = movie.NumberInStock; } _context.SaveChanges(); return(RedirectToAction("Index", "Movies")); }
public ActionResult Save(Customer customer) { if (!ModelState.IsValid) { var viewModel = new NewCustomerViewModel { Customer = customer, MembershipTypes = _context.MembershipTypes.ToList() }; return View("CustomerForm", viewModel); } if (customer.Id==0) _context.Customers.Add(customer); else { var costumerInDb = _context.Customers.Single(c => c.Id == customer.Id); costumerInDb.Name = customer.Name; costumerInDb.BirthDate = customer.BirthDate; costumerInDb.MembershipTypeId = customer.MembershipTypeId; costumerInDb.IsSubscribedToNewsLetter = customer.IsSubscribedToNewsLetter; } _context.SaveChanges(); return RedirectToAction("Index", "Customers"); }
public static bool RemoveRentedMovie(int rentedMovieID) { try { _context.RentedMovies.Remove(_context.RentedMovies.Find(rentedMovieID)); //_context.RentedMovies.Remove(ReturnRentedMovieForCustomerID(customerID)); _context.Database.Log = Console.WriteLine; _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public static bool RegisterNewCustomer(Customer newCustomer) { try { _context.Customers.Add(newCustomer); _context.Database.Log = Console.WriteLine; _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }