Ejemplo n.º 1
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Movie).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovieExists(Movie.Title))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Movies.Add(Movie);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Movie = await _context.Movies.FindAsync(id);

            if (Movie != null)
            {
                _context.Movies.Remove(Movie);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        private static async Task UpdateTheatersAsync(ComeAndTicketContext db, IEnumerable <Theater> theatersFromWeb)
        {
            await db.Theaters.LoadAsync();

            var theatersByUrl = await db.Theaters.ToDictionaryAsync(
                t => t.Url,
                t => t,
                StringComparer.OrdinalIgnoreCase);

            foreach (var theaterFromWeb in theatersFromWeb)
            {
                if (theatersByUrl.TryGetValue(theaterFromWeb.Url, out Theater theaterFromDb))
                {
                    theaterFromDb.Name = theaterFromWeb.Name;
                }
                else
                {
                    db.Theaters.Add(theaterFromWeb);
                }
            }
            await db.SaveChangesAsync();
        }
        private static async ValueTask UpdateMarketsAsync(ComeAndTicketContext db, IEnumerable <Market> marketsFromWeb)
        {
            await db.Markets.LoadAsync();

            var marketsByName = await db.Markets.ToDictionaryAsync(
                m => m.Name,
                m => m,
                StringComparer.CurrentCultureIgnoreCase);

            foreach (var marketFromWeb in marketsFromWeb)
            {
                if (marketsByName.TryGetValue(marketFromWeb.Name, out Market marketFromDb))
                {
                    marketFromDb.Name = marketFromWeb.Name;
                }
                else
                {
                    db.Markets.Add(marketFromWeb);
                }
            }
            await db.SaveChangesAsync();
        }