Beispiel #1
0
        //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);
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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));
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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());
        }
Beispiel #9
0
 public async Task <int> SaveChangesAsync()
 {
     return(await dbContext.SaveChangesAsync());
 }