Beispiel #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MetaTagExists(MetaTag.MetaTagId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedBusiness, string[] selectedFacility, string[] selectedMetaTags)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Initiative).State = EntityState.Modified;
            //This saves the parent Entity and one-many child relationships
            await _context.SaveChangesAsync();

            //This saves the Masny-to-Many relationships
            var initiativeToUpdate = await _context.Initiative
                                     .Include(i => i.InitiativeBusiness)
                                     .ThenInclude(i => i.Business)
                                     .Include(i => i.InitiativeFacility)
                                     .ThenInclude(i => i.Facility)
                                     .Include(i => i.InitiativeMetaTag)
                                     .ThenInclude(i => i.MetaTag)
                                     .FirstOrDefaultAsync(s => s.InitiativeId == id);

            UpdateInitiativeBusiness(_context, selectedBusiness, initiativeToUpdate);
            UpdateInitiativeFacility(_context, selectedFacility, initiativeToUpdate);
            UpdateInitiativeMetaTags(_context, selectedMetaTags, initiativeToUpdate);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InitiativeExists(Initiative.InitiativeId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

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