Ejemplo 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 enemySetID, int enemyID)
        {
            var eisToUpdate = await _context.EnemyInSets.FindAsync(enemySetID, enemyID);

            if (eisToUpdate == null)
            {
                return(NotFound());
            }

            // if we've changed the enemyID (which is part of the key)
            // then we actually need to delete this EIS and make a new one
            if (enemyID != EnemyInSet.EnemyID)
            {
                // delete EIS and make new one
                try
                {
                    _context.EnemyInSets.Remove(eisToUpdate);
                    await _context.SaveChangesAsync();

                    var emptyEIS = new EnemyInSet();

                    emptyEIS.EnemySetID = enemySetID;

                    if (await TryUpdateModelAsync <EnemyInSet>(
                            emptyEIS,
                            "enemyinset",
                            d => d.EnemyID, d => d.Count, d => d.Name, d => d.Description))
                    {
                        _context.EnemyInSets.Add(emptyEIS);
                        await _context.SaveChangesAsync();

                        return(RedirectToPage("/EnemySets/Details", new { id = enemySetID }));
                    }

                    return(Page());
                }
                catch (DbUpdateException /* ex */)
                {
                    //Log the error (uncomment ex variable name and write a log.)
                    return(RedirectToAction("./Edit",
                                            new { enemySetID, enemyID, saveChangesError = true }));
                }
            }

            // otherwise just update
            if (await TryUpdateModelAsync <EnemyInSet>(
                    eisToUpdate,
                    "enemyinset",
                    d => d.EnemyID, d => d.Count, d => d.Name, d => d.Description))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("/EnemySets/Details", new { id = enemySetID }));
            }

            return(Page());
        }
Ejemplo n.º 2
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync(int enemySetID)
        {
            var emptyEIS = new EnemyInSet();

            emptyEIS.EnemySetID = enemySetID;

            if (await TryUpdateModelAsync <EnemyInSet>(
                    emptyEIS,
                    "enemyinset", // Prefix for form value.
                    d => d.EnemyID, d => d.Count, d => d.Name, d => d.Description))
            {
                _context.EnemyInSets.Add(emptyEIS);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/EnemySets/Details", new { id = enemySetID }));
            }

            return(Page());
        }