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")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.MetaTag.Add(MetaTag); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } MetaTag = await _context.MetaTag.FindAsync(id); if (MetaTag != null) { _context.MetaTag.Remove(MetaTag); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Initiative = await _context.Initiative.FindAsync(id); if (Initiative != null) { _context.Initiative.Remove(Initiative); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string[] selectedBusiness, string[] selectedFacility, string[] selectedMetaTags) { if (!ModelState.IsValid) { return(Page()); } /*******************************************/ //Get the entity var newInitiative = new Initiative(); // Add Business if (selectedBusiness != null) { newInitiative.InitiativeBusiness = new List <InitiativeBusiness>(); foreach (var business in selectedBusiness) { var initiativeBusinessToAdd = new InitiativeBusiness { BusinessId = int.Parse(business) }; newInitiative.InitiativeBusiness.Add(initiativeBusinessToAdd); } } // Add Facility if (selectedFacility != null) { newInitiative.InitiativeFacility = new List <InitiativeFacility>(); foreach (var facility in selectedFacility) { var initiativeFacilityToAdd = new InitiativeFacility { FacilityId = int.Parse(facility) }; newInitiative.InitiativeFacility.Add(initiativeFacilityToAdd); } } // Add Meta Tags if (selectedMetaTags != null) { newInitiative.InitiativeMetaTag = new List <InitiativeMetaTag>(); foreach (var metaTag in selectedMetaTags) { var initiativeMetaTagToAdd = new InitiativeMetaTag { MetaTagId = int.Parse(metaTag) }; newInitiative.InitiativeMetaTag.Add(initiativeMetaTagToAdd); } } // Add Facility //the method of updating below is used as a security measure and to prevent over posting if (await TryUpdateModelAsync <Initiative>( newInitiative, "Initiative", i => i.ARBDate, i => i.EngagementName, i => i.EngagementIdentifier, i => i.EngagementTypeId, i => i.CurrentStatusId, i => i.SolutionTypeId, i => i.LocationId, i => i.PHI, i => i.PCI, i => i.UpStreamSystem, i => i.DownStreamSystem, i => i.ProjectStartDate, i => i.Resource, i => i.ReceiveDate, i => i.StartDate, i => i.CompleteDate, i => i.LastModifiedDate, i => i.ModifiedUserName, i => i.IsActive)) { _context.Initiative.Add(newInitiative); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedMetaTagData(_context, newInitiative); return(Page()); /*************************************** * _context.Initiative.Add(Initiative); * await _context.SaveChangesAsync(); * * return RedirectToPage("./Index");*/ }