// 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?id, string[] selectedTags) { if (id == null) { return(NotFound()); } var personToUpdate = await _context.People .Include(x => x.PersonTags) .ThenInclude(x => x.Tag) .FirstOrDefaultAsync(s => s.ID == id); if (personToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Person>( personToUpdate, "person", s => s.FirstMidName, s => s.LastName)) { UpdatePersonTags(_context, selectedTags, personToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } UpdatePersonTags(_context, selectedTags, personToUpdate); PopulatePersonTags(_context, personToUpdate); return(Page()); }
// 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( string[] selectedTags) { var newJob = new Job(); if (selectedTags != null) { newJob.JobTags = new List <JobTag>(); foreach (var tag in selectedTags) { var tagtoAdd = new JobTag { TagID = int.Parse(tag) }; newJob.JobTags.Add(tagtoAdd); } } if (await TryUpdateModelAsync <Job>( newJob, "job", s => s.ID, s => s.CompanyID, s => s.Title, s => s.CareerLevel, s => s.City, s => s.Description)) { _context.Jobs.Add(newJob); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } UpdateJobTags(_context, selectedTags, newJob); PopulateJobTags(_context, newJob); PopulateCompaniesDropDownList(_context, newJob.CompanyID); return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Person = await _context.People .Include(x => x.PersonTags).SingleAsync(x => x.ID == id);; if (Person == null) { return(NotFound()); } try { var personTags = await _context.PersonTags .Where(d => d.PersonID == id) .ToListAsync(); personTags.ForEach(d => _context.PersonTags.Remove(d)); _context.People.Remove(Person); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) return(RedirectToAction("./Delete", new { id, saveChangesError = true })); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Company = await _context.Companies.FindAsync(id); if (Company != null) { var jobs = await _context.Jobs .Where(d => d.CompanyID == id) .ToListAsync(); foreach (var job in jobs) { var jobtags = await _context.JobTags .Where(d => d.JobID == job.ID) .ToListAsync(); jobtags.ForEach(d => _context.JobTags.Remove(d)); _context.Jobs.Remove(job); } _context.Companies.Remove(Company); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// 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() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Company).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompanyExists(Company.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// 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?id, string[] selectedTags) { if (id == null) { return(NotFound()); } var jobToUpdate = await _context.Jobs .Include(i => i.Company) .Include(i => i.JobTags) .ThenInclude(i => i.Tag) .FirstOrDefaultAsync(s => s.ID == id); if (jobToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Job>( jobToUpdate, "job", s => s.ID, s => s.CompanyID, s => s.Title, s => s.CareerLevel, s => s.City, s => s.Description)) { UpdateJobTags(_context, selectedTags, jobToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } UpdateJobTags(_context, selectedTags, jobToUpdate); PopulateJobTags(_context, jobToUpdate); PopulateCompaniesDropDownList(_context, jobToUpdate.CompanyID); return(Page()); }
// 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() { if (!ModelState.IsValid) { return(Page()); } _context.Companies.Add(Company); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Tag = await _context.Tags.FindAsync(id); if (Tag != null) { _context.Tags.Remove(Tag); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Job = await _context.Jobs.Include(x => x.JobTags).SingleAsync(x => x.ID == id); if (Job != null) { var jobtags = await _context.JobTags .Where(d => d.JobID == id) .ToListAsync(); jobtags.ForEach(d => _context.JobTags.Remove(d)); _context.Jobs.Remove(Job); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// 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( string[] selectedTags) { var newPerson = new Person(); if (selectedTags != null) { newPerson.PersonTags = new List <PersonTag>(); foreach (var tag in selectedTags) { var tagToAdd = new PersonTag { TagID = int.Parse(tag) }; newPerson.PersonTags.Add(tagToAdd); } } if (await TryUpdateModelAsync <Person>( newPerson, "person", s => s.ID, s => s.BirthDate, s => s.CanRelocate, s => s.City, s => s.CurrentCareerLevel, s => s.Email, s => s.ExperienceType, s => s.FirstMidName, s => s.LastName, s => s.Phone, s => s.ShortBio )) { _context.People.Add(newPerson); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } UpdatePersonTags(_context, selectedTags, newPerson); PopulatePersonTags(_context, newPerson); return(Page()); }
public async Task Save() { await _context.SaveChangesAsync(); }