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 lootID, int mediaID)
        {
            var lmToUpdate = await _context.LootMedias.FindAsync(lootID, mediaID);

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

            // if we've changed the MediaID (which is part of the key)
            // then we actually need to delete this EM and make a new one
            if (mediaID != LootMedia.MediaID)
            {
                // delete EM and make new one
                try
                {
                    _context.LootMedias.Remove(lmToUpdate);
                    await _context.SaveChangesAsync();

                    var emptyLM = new LootMedia();

                    emptyLM.LootID = lootID;

                    if (await TryUpdateModelAsync <LootMedia>(
                            emptyLM,
                            "lootmedia",
                            d => d.MediaID, d => d.MediaLabel))
                    {
                        _context.LootMedias.Add(emptyLM);
                        await _context.SaveChangesAsync();

                        return(RedirectToPage("/Loots/Details", new { id = lootID }));
                    }

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

            // otherwise just update
            if (await TryUpdateModelAsync <LootMedia>(
                    lmToUpdate,
                    "lootmedia",
                    d => d.MediaID, d => d.MediaLabel))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("/Loots/Details", new { id = lootID }));
            }

            return(Page());
        }
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync(int lootID)
        {
            var emptyLM = new LootMedia();

            emptyLM.LootID = lootID;

            if (await TryUpdateModelAsync <LootMedia>(
                    emptyLM,
                    "lootmedia", // Prefix for form value.
                    d => d.MediaID, d => d.MediaLabel))
            {
                _context.LootMedias.Add(emptyLM);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/Loots/Details", new { id = lootID }));
            }

            return(Page());
        }