public Movie Create(MoviePostModel movieDTO) { Movie addMovie = MoviePostModel.ToMovie(movieDTO); DbContext.Movies.Add(addMovie); DbContext.SaveChanges(); return(addMovie); }
//acum mutam logica din Controller pe Service. //Nu il eliminam dar Controller-ul va apela Service si nu va mai apela UI-ul Service-ul public Movie Create(MoviePostModel movie) { Movie toAdd = MoviePostModel.ToMovie(movie); context.Movies.Add(toAdd); context.SaveChanges(); return(toAdd); }
public Movie Create(MoviePostModel movie, User addedBy) { Movie toAdd = MoviePostModel.ToMovie(movie); toAdd.Owner = addedBy; //adaugam persoana care a adaugat acest Movie movie context.Movies.Add(toAdd); context.SaveChanges(); return(toAdd); }
//acum mutam logica din Controller pe Service. //Nu il eliminam dar Controller-ul va apela Service si nu va mai apela UI-ul Service-ul public Movie Create(MoviePostModel movie, User addedBy) { Movie toAdd = MoviePostModel.ToMovie(movie); toAdd.Owner = addedBy; context.Movies.Add(toAdd); context.SaveChanges(); return(toAdd); }
public Movie Create(MoviePostModel movie, User addedBy) { Movie toAdd = MoviePostModel.ToMovie(movie); movie.DateClosed = null; movie.DateAdded = DateTime.Now; toAdd.Owner = addedBy; context.Movies.Add(toAdd); context.SaveChanges(); return(toAdd); }
/// <summary> /// Create a new Movie, using MoviePostModel /// </summary> /// <param name="movie">New Movie object</param> /// <returns></returns> public Movie Create(MoviePostModel movie) { Movie convertedMovie = MoviePostModel.ToMovie(movie); if (convertedMovie == null) { return(null); } Context.Movies.Add(convertedMovie); Context.SaveChanges(); return(convertedMovie); }
/// <summary> /// Update or Add /// </summary> /// <param name="id">Id for update</param> /// <param name="movies">New Movie object we want to add</param> /// <returns></returns> public Movie Upsert(int id, MoviePostModel movies) { var existing = Context.Movies.AsNoTracking().FirstOrDefault(c => c.Id == id); if (existing == null) { var movie = Context.Movies.Add(MoviePostModel.ToMovie(movies)); Context.SaveChanges(); return(movie.Entity); } var res = MoviePostModel.ToUpdateMovie(movies, existing); Context.SaveChanges(); return(res); }
public Movie Upsert(int id, MoviePostModel movie) { var existing = context.Movies.AsNoTracking().FirstOrDefault(f => f.Id == id); if (existing == null) { Movie toAdd = MoviePostModel.ToMovie(movie); context.Movies.Add(toAdd); context.SaveChanges(); return(toAdd); } Movie toUpdate = MoviePostModel.ToMovie(movie); toUpdate.Id = id; context.Movies.Update(toUpdate); context.SaveChanges(); return(toUpdate); }