Exemple #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 lootSetID, int lootID)
        {
            var lisToUpdate = await _context.LootInSets.FindAsync(lootSetID, lootID);

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

            // if we've changed the lootID (which is part of the key)
            // then we actually need to delete this LIS and make a new one
            if (lootID != LootInSet.LootID)
            {
                // delete LIS and make new one
                try
                {
                    _context.LootInSets.Remove(lisToUpdate);
                    await _context.SaveChangesAsync();

                    var emptyLIS = new LootInSet();

                    emptyLIS.LootSetID = lootSetID;

                    if (await TryUpdateModelAsync <LootInSet>(
                            emptyLIS,
                            "lootinset",
                            d => d.LootID, d => d.Count, d => d.Name, d => d.Description))
                    {
                        _context.LootInSets.Add(emptyLIS);
                        await _context.SaveChangesAsync();

                        return(RedirectToPage("/LootSets/Details", new { id = lootSetID }));
                    }

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

            // otherwise just update
            if (await TryUpdateModelAsync <LootInSet>(
                    lisToUpdate,
                    "lootinset",
                    d => d.LootID, d => d.Count, d => d.Name, d => d.Description))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("/LootSets/Details", new { id = lootSetID }));
            }

            return(Page());
        }
Exemple #2
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync(int lootSetID)
        {
            var emptyLIS = new LootInSet();

            emptyLIS.LootSetID = lootSetID;

            if (await TryUpdateModelAsync <LootInSet>(
                    emptyLIS,
                    "lootinset", // Prefix for form value.
                    d => d.LootID, d => d.Count, d => d.Name, d => d.Description))
            {
                _context.LootInSets.Add(emptyLIS);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/LootSets/Details", new { id = lootSetID }));
            }

            return(Page());
        }