public async Task AddAsync(T entity) { EntityEntry entry = context.Entry(entity); if (entry.State != EntityState.Detached) { entry.State = EntityState.Added; } else { await context.Set <T>().AddAsync(entity); } }
public async Task <IActionResult> PutGenero(int id, Genero genero) { if (id != genero.IdGenero) { return(BadRequest()); } _context.Entry(genero).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GeneroExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutFilme(int id, Filme filme) { if (id != filme.Tconst) { return(BadRequest()); } _context.Entry(filme).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FilmeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "MovieId,Name,Yor,Poster")] Movie movie, int ProducerId, string[] SelectedActorIds) { var existingactor = db.Database.SqlQuery <QueryResult>("SELECT * FROM ActorMovie").Where(x => x.intMovieid == movie.MovieId).ToList(); List <int> viewselectedactor = new List <int>(); foreach (var sc in SelectedActorIds) { viewselectedactor.Add(Int32.Parse(sc)); } int[] viewselectedlist1 = viewselectedactor.ToArray(); int[] lstTableItems = existingactor.Select(x => x.intActorId).ToArray(); int[] addactorLst = viewselectedlist1.Except(lstTableItems).ToArray(); int[] removeactorLst = lstTableItems.Except(viewselectedlist1.Except(addactorLst)).ToArray(); AddSeletedActors(addactorLst, movie.MovieId); RemoveDeselectedActors(removeactorLst, movie.MovieId); if (movie.Poster == null) { var mv = db.Movies.Find(movie.MovieId); db.Entry(mv).State = EntityState.Detached; movie.Poster = mv.Poster; } else { var idforimagename = 1; try { try { idforimagename = movie.MovieId; } catch (Exception e) { } var poster = Request.Files["Poster"]; if (poster.ContentLength >= 1048576) { ViewBag.BrochureError = "Error : Image size should not exceed 1MB !"; return(View(poster)); } var imageExtesnion = poster.FileName.Substring(poster.FileName.LastIndexOf('.')); poster.SaveAs(Server.MapPath("~/") + @"Images/Movies/" + idforimagename + imageExtesnion); movie.Poster = "../../Images/Movies/" + idforimagename + imageExtesnion; } catch (Exception) { } } if (ModelState.IsValid) { var mv = db.Movies.Find(movie.MovieId); db.Entry(mv).State = EntityState.Detached; movie.Actors = mv.Actors; movie.ProducerId = ProducerId; db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movie)); }
public void UpdateMovie(IMDB movie) { _imdbContext.Entry(movie).State = System.Data.Entity.EntityState.Modified; }