//public async Task<List<T>> WhereByUserId(int? id, Func<T, int> property, PaginationFilter paginationFilter = null) //{ // if (paginationFilter != null) // { // return await Context.Set<T>().Skip((paginationFilter.PageNumber - 1) * paginationFilter.PageSize) // .Take(paginationFilter.PageSize) // .Where(x => property(x) == id) // .ToListAsync(); // } // return await Context.Set<T>().Where(x => property(x) == id).ToListAsync(); //} public async Task <T> Delete(T entity) { Context.Set <T>().Remove(entity); await Context.SaveChangesAsync(); return(entity); }
public async Task <IActionResult> Create([Bind("Id,CompanyName,CompanyDescription")] Company company) { if (ModelState.IsValid) { _context.Add(company); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(company)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName")] Actor actor) { if (ModelState.IsValid) { _context.Add(actor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(actor)); }
public async Task <IActionResult> Create([Bind("Id,FullName,BornYear")] Producer producer) { if (ModelState.IsValid) { _context.Add(producer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(producer)); }
public async Task <IActionResult> Create([Bind("Id,Code")] Language language) { if (ModelState.IsValid) { _context.Add(language); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(language)); }
public async Task <IActionResult> Create([Bind("Id,MovieTitle,LanguageId,Prod_year,MovieDescription,ProducerId,CompanyId")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CompanyId"] = new SelectList(_context.Company, "Id", "Id", movie.CompanyId); ViewData["LanguageId"] = new SelectList(_context.Language, "Id", "Id", movie.LanguageId); ViewData["ProducerId"] = new SelectList(_context.Producer, "Id", "Id", movie.ProducerId); return(View(movie)); }
private async Task AddNecessaryCountriesAsync(List <ProductionCountry> countries) { foreach (var country in countries) { var countryEntity = context.Countries.FirstOrDefault(x => x.Name == ParseCountryName(country.Name)); if (countryEntity == null) { await context.Countries.AddAsync(new Country { Name = country.Name }); } } await context.SaveChangesAsync(); }
public async Task <IActionResult> Create(MovieCreateModel model) { if (ModelState.IsValid) { var movie = new Movie { MovieId = model.Id, Title = model.Title, OriginalTitle = model.OriginalTitle, Description = model.Description, ProductionYear = model.ProductionYear, RunningLength = model.RunningLengthHours * 60 + model.RunningLengthMinutes, GenreId = model.GenreId }; _db.Movies.Add(movie); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(await Create()); }
public async Task <int> SaveChangesAsync() { return(await dbContext.SaveChangesAsync()); }