public async Task <ActionResult <Ticket> > UpdateTicketById(int id, Ticket ticket) { if (ticket.ticketId != id) { return(BadRequest()); } if (!TicketExist(id)) { return(NotFound()); } _context.Entry(ticket).State = EntityState.Modified; try { await _context.SaveChangesAsync(); if (!TicketExist(id)) { return(NotFound()); } } catch (DbUpdateConcurrencyException) { throw new Exception("Traffic Problem, please try again later"); } return(NoContent()); }
public IActionResult Edit(Movie movies) { _context.Attach(movies); _context.Entry(movies).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("index")); }
public IHttpActionResult PutMovie(int id, Movie movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != movie.Id) { return(BadRequest()); } db.Entry(movie).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IEnumerable <Borrow> > GetAll() { var borrows = await _movieContext.Borrow.ToListAsync(); borrows.ForEach(x => { _movieContext.Entry(x).Reference(y => y.Client).LoadAsync(); }); borrows.ForEach(x => { _movieContext.Entry(x).Reference(y => y.Movie).LoadAsync(); }); return(borrows); }
public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
public async Task AddAsync(Order order) { _context.Orders.Add(order); _context.Entry <ApplicationUser>(order.User).State = EntityState.Unchanged; _context.Entry(order.ShippingAddress.User).State = EntityState.Unchanged; //_context.Entry(order.ShippingAddress).State = order.ShippingAddress.Id == 0 ? EntityState.Added : EntityState.Modified; await _context.SaveChangesAsync(); }
public ActionResult Edit([Bind(Include = "MovieID,CategoryName,MovieName,Description,Rating")] Movie movie) { if (ModelState.IsValid) { db.Entry(movie).State = EntityState.Modified; movie.User = User.Identity.Name; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movie)); }
public ActionResult Edit([Bind(Include = "Id,Name,Year,IsTvShow,IsFavorite")] Movie movie) { if (ModelState.IsValid) { db.Entry(movie).State = EntityState.Modified; db.Entry(movie).Property(p => p.Rate).IsModified = false; db.Entry(movie).Property(p => p.Watched).IsModified = false; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movie)); }
public async Task <Boolean> Update(Director director) { var directorInDb = _context.Directors.Single(d => d.Id == director.Id); if (directorInDb != null) { _context.Entry <Director>(directorInDb).State = EntityState.Detached; _context.Directors.Update(director); await _context.SaveChangesAsync(); return(true); } return(false); }
public async Task <Boolean> Update(Movie movie) { var movieInDb = _context.Movies.Single(m => m.Id == movie.Id); if (movieInDb != null) { _context.Entry <Movie>(movieInDb).State = EntityState.Detached; _context.Movies.Update(movie); await _context.SaveChangesAsync(); return(true); } return(false); }
public void Update(Movie movie) { var RecordExist = context.Movies.Find(movie.Id); if (RecordExist == null) { context.Movies.Add(movie); } else { context.Entry(RecordExist).State = EntityState.Detached; context.Entry(movie).State = EntityState.Modified; } }
public ActionResult EditMovie([Bind(Include = "ID,TrailerID,MovieName,writer,stars,videoLink,brief")] Movie Movie) { //wait for date that the user enter and change the Movie if (ModelState.IsValid) { db.Entry(Movie).State = EntityState.Modified; db.SaveChanges(); } else { TempData["alertMessage"] = "<script>alert('Error in input');</script>"; } return(RedirectToAction("Index")); }
public async Task <IActionResult> PutComment(long id, Comment comment) { if (id != comment.Id) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUsers([FromRoute] int id, [FromBody] Users users) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != users.Id) { return(BadRequest()); } _context.Entry(users).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMovie([FromRoute] int id, [FromBody] Movie movie) { if (!ModelState.IsValid || movie == null) { return(BadRequest(ModelState)); } if (id != movie.Id) { return(BadRequest()); } _context.Entry(movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { return(BadRequest(Json("Couldn't update item!"))); } } return(NoContent()); }
public async Task <IHttpActionResult> PutDirector(int id, Director director) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != director.Id) { return(BadRequest()); } db.Entry(director).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DirectorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> UpdateActor(int id, [FromBody] Actor actor) { if (actor == null || actor.Id != id) { return(BadRequest()); } _context.Entry(actor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMovie(int id, Movie movie) { if (id != movie.Id) { return(BadRequest()); } _context.Entry(movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(int id, string title, string director, DateTime releaseDate, decimal gross, double rating, string imageUrl, int genreID, HttpPostedFileBase image) { var movie = db.Movies.Find(id); if (ModelState.IsValid && movie != null) { movie.Title = title; movie.Director = director; movie.ReleaseDate = releaseDate; movie.Gross = gross; movie.Rating = rating; movie.ImageUrl = imageUrl; movie.GenreID = genreID; //if image object is not empty update the photo attribute, using image info. if (image != null) { movie.ImageMimeType = image.ContentType; movie.ImageFile = new byte[image.ContentLength]; //save the photo file by using image.InputStream.Read method. image.InputStream.Read(movie.ImageFile, 0, image.ContentLength); } db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GenreID = new SelectList(db.Genres, "GenreID", "Name", movie.GenreID); return(View(movie)); }
public async Task <IActionResult> PutMovieItem(int id, MovieItem movieItem) { if (id != movieItem.Id) { return(BadRequest()); } await Task.Run(() => { _context.Entry(movieItem).State = EntityState.Modified; }); await _context.SaveChangesAsync(); try { } catch (DbUpdateConcurrencyException) { if (!MovieItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutCinema(string id, Cinema cinema) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != cinema.CinemaID) { return(BadRequest()); } db.Entry(cinema).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CinemaExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task UpdateUserMovieRating(IUserMovieRatingDto userMovieRatingDto) { using (var context = new MovieContext()) { var userMovieRating = context.UserMovieRating.FirstOrDefault(x => x.UserId == userMovieRatingDto.UserId && x.MovieId == userMovieRatingDto.MovieId); if (userMovieRating != null) { userMovieRating.Rating = userMovieRatingDto.Rating; context.UserMovieRating.Attach(userMovieRating); context.Entry(userMovieRating).State = EntityState.Modified; } else { userMovieRating = new UserMovieRating { UserId = userMovieRatingDto.UserId, MovieId = userMovieRatingDto.MovieId, Rating = userMovieRatingDto.Rating }; context.UserMovieRating.Add(userMovieRating); } await context.SaveChangesAsync(); } }
public async Task <IActionResult> PutLoginModel(int id, LoginModel loginModel) { if (id != loginModel.Id) { return(BadRequest()); } _context.Entry(loginModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoginModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(Movie emovie) { //update db with new values // return to detail page db.Entry(emovie).State = EntityState.Modified; db.SaveChanges(); return(Redirect("ListAll")); }
public IActionResult _DeleteMovie(ManageMovie model) { Movies movies = _context.Set <Movies>().SingleOrDefault(c => c.Id == model.Id); _context.Entry(movies).State = EntityState.Deleted; _context.SaveChanges(); return(RedirectToAction("Index")); }
public IHttpActionResult PutMovie(int id, Movie movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != movie.ID) { return(BadRequest()); } var usersWatched = movie.UsersWatched; movie.UsersWatched = null; if (usersWatched != null && usersWatched.Count > 0) { foreach (User u in usersWatched) { db.Entry(u).State = EntityState.Modified; } } db.Entry(movie).State = EntityState.Modified; db.Entry(movie).Collection(x => x.UsersWatched).Load(); var userIDs = usersWatched.Select(x => x.ID); var newUsers = db.Users.Where(x => userIDs.Contains(x.ID)).ToList(); movie.UsersWatched = newUsers; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Put(int id, Movie movie) { movie.Id = id; db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return(Ok()); }
public void Put(int id, [FromBody] User value) { var user = Get(id); user.Name = Value.Name; user.Email = value.Email; _ctx.Entry(user).state = EntityState.Modified; _ctx.SaveChanges(); }
public async Task <ActionResult> EditMovie(AppMovie appMovie) { _movieContext.Entry(appMovie).State = EntityState.Modified; if (await _movieContext.SaveChangesAsync() > 0) { return(Ok()); } return(BadRequest("Failed to update Movie!")); }
public IHttpActionResult Put(int id, Rater rater) { rater.Id = id; db.Entry(rater).State = EntityState.Modified; // Step 3 db.SaveChanges(); return(Ok()); }