public async Task <ActionResult> Create([Bind(Include = "MovieId,Title,Length,Price,Amount,Date")] Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(movie)); }
public static void addNewCartToDB(int userId, int movieId) { var db = new MovieStoreEntities(); Cart newCart = new Cart { UserId = userId, MovieId = movieId, Count = 1 }; var currCart = db.Carts.SqlQuery("select * from carts where dbo.Carts.UserId = {0} and dbo.Carts.MovieId = {1}", userId, movieId); if (currCart.ToList().Count > 0) { //meaning its already exist db.Database.ExecuteSqlCommand("UPDATE dbo.Carts SET Count = Count+1 WHERE dbo.Carts.UserId = {0} and dbo.Carts.MovieId = {1} ", userId, movieId); } else { //meaning its a new cart. db.Carts.Add(newCart); } db.SaveChangesAsync(); }