Esempio n. 1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedTeams)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var alienToUpdate = await _context.Alien
                                .Include(i => i.Planet)
                                .Include(i => i.AlienTeams)
                                .ThenInclude(i => i.Team)
                                .FirstOrDefaultAsync(s => s.ID == id);

            if (alienToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Alien>(
                    alienToUpdate,
                    "Alien",
                    i => i.Name, i => i.Age,
                    i => i.Color, i => i.ArrivedOnEarth, i => i.PlanetID))
            {
                UpdateAlienTeams(_context, selectedTeams, alienToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            UpdateAlienTeams(_context, selectedTeams, alienToUpdate);
            PopulateAssignedTeamData(_context, alienToUpdate);
            return(Page());
        }
Esempio n. 2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedTeams)
        {
            var newAlien = new Alien();

            if (selectedTeams != null)
            {
                newAlien.AlienTeams = new List <AlienTeam>();
                foreach (var cat in selectedTeams)
                {
                    var catToAdd = new AlienTeam
                    {
                        TeamID = int.Parse(cat)
                    };
                    newAlien.AlienTeams.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Alien>(
                    newAlien,
                    "Alien",
                    i => i.Name, i => i.Age,
                    i => i.Color, i => i.ArrivedOnEarth, i => i.PlanetID))
            {
                _context.Alien.Add(newAlien);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedTeamData(_context, newAlien);
            return(Page());
        }
Esempio n. 3
0
        // To protect from overposting attacks, 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(Planet).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlanetExists(Planet.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, 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.AlienTeam.Add(AlienTeam);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Team = await _context.Team.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
        public async Task <T> SaveAsync(T entity)
        {
            await _context.SaveChangesAsync();

            return(entity);
        }