// 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(Partner).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PartnerExists(Partner.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[] selectedCategories) { if (id == null) { return(NotFound()); } var drugToUpdate = await _context.Drug .Include(i => i.Partner) .Include(i => i.DrugCategories) .ThenInclude(i => i.Category) .FirstOrDefaultAsync(s => s.ID == id); if (drugToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Drug>( drugToUpdate, "Drug", i => i.Name, i => i.Producer, i => i.Price, i => i.PublishingDate, i => i.Partner)) { UpdateDrugCategories(_context, selectedCategories, drugToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } //Apelam UpdateDrugCategories pentru a aplica informatiile din checkboxuri la entitatea Books care //este editata UpdateDrugCategories(_context, selectedCategories, drugToUpdate); PopulateAssignedCategoryData(_context, drugToUpdate); 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[] selectedCategories) { var newDrug = new Drug(); if (selectedCategories != null) { newDrug.DrugCategories = new List <DrugCategory>(); foreach (var cat in selectedCategories) { var catToAdd = new DrugCategory { CategoryID = int.Parse(cat) }; newDrug.DrugCategories.Add(catToAdd); } } if (await TryUpdateModelAsync <Drug>( newDrug, "Drug", i => i.Name, i => i.Producer, i => i.Price, i => i.PublishingDate, i => i.PartnerID)) { _context.Drug.Add(newDrug); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newDrug); 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.Category.Add(Category); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Partner = await _context.Partner.FindAsync(id); if (Partner != null) { _context.Partner.Remove(Partner); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Drug = await _context.Drug.FindAsync(id); if (Drug != null) { _context.Drug.Remove(Drug); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Category = await _context.Category.FindAsync(id); if (Category != null) { _context.Category.Remove(Category); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }