public override async Task Execute(OrganismClassification model, OrganismDbContext _context) { _context.Remove(_context.Kingdoms.Include(i => i.Phylums) .Single(i => i.KingdomTID == model.KingdomID).Phylums .Single(i => i.PhylumTID == model.PhylumID)); await _context.SaveChangesAsync(); }
//=INDEX=============================================================== // GET: Organism public async Task <IActionResult> Index() { OrganismClassification OrganismC = new OrganismClassification(); await TryUpdateModelAsync(OrganismC); ChosenTaxons viewModel = await ChosenTaxonsFiller.Fill(_context, OrganismC); return(View(viewModel)); }
// GET: Learning/AddSource/5 public async Task <IActionResult> SourceIndex(int learningSetID) { OrganismClassification OrganismC = new OrganismClassification(); await TryUpdateModelAsync(OrganismC); ChosenTaxons viewModel = await ChosenTaxonsFiller.Fill(_context, OrganismC); ViewBag.LearningSetID = learningSetID; return(View(viewModel)); }
public override async Task Execute(OrganismClassification model, OrganismDbContext _context) { _context.Remove(_context.Kingdoms .Include(i => i.Phylums).ThenInclude(i => i.Classes).ThenInclude(i => i.Orders) .ThenInclude(i => i.Families) .Single(i => i.KingdomTID == model.KingdomID).Phylums .Single(i => i.PhylumTID == model.PhylumID).Classes .Single(i => i.ClassTID == model.ClassID).Orders .Single(i => i.OrderTID == model.OrderID).Families .Single(i => i.FamilyTID == model.FamilyID)); await _context.SaveChangesAsync(); }
public async Task Delete(OrganismClassification model, OrganismDbContext _context) { var action = typeof(DeleteBase).Assembly.GetTypes() .Where(t => t.IsSubclassOf(typeof(DeleteBase)) && !t.IsAbstract) .Select(t => (DeleteBase)Activator.CreateInstance(t)) .FirstOrDefault(a => a.ShouldExecute(model.Taxon)); if (action == null) { throw new ArgumentException("Unknown case."); } await action.Execute(model, _context); }
public async Task <IActionResult> DeleteConfirmed() { OrganismClassification organism = new OrganismClassification(); if (await TryUpdateModelAsync(organism)) { try { await new DeleteStrategyContext().Delete(organism, _context); } catch (ArgumentException) { return(NotFound()); } } return(RedirectToAction("Index")); }
public abstract Task Execute(OrganismClassification organism, OrganismDbContext _context);
public static async Task <ChosenTaxons> Fill(OrganismDbContext _context, OrganismClassification OIDs) { ChosenTaxons viewModel = new ChosenTaxons { Kingdoms = await _context.Kingdoms .Include(i => i.Phylums) .ThenInclude(i => i.Classes) .ThenInclude(i => i.Orders) .ThenInclude(i => i.Families) .ThenInclude(i => i.Genusses) .ThenInclude(i => i.Species) .OrderBy(i => i.Name) .ToListAsync() }; if (OIDs.KingdomID != null) { viewModel.ChosenKingdom = viewModel.Kingdoms .Single(x => x.KingdomTID == OIDs.KingdomID); } if (OIDs.PhylumID != null) { viewModel.ChosenPhylum = viewModel.ChosenKingdom.Phylums .Single(x => x.PhylumTID == OIDs.PhylumID); } if (OIDs.ClassID != null) { viewModel.ChosenClass = viewModel.ChosenPhylum.Classes .Single(x => x.ClassTID == OIDs.ClassID); } if (OIDs.OrderID != null) { viewModel.ChosenOrder = viewModel.ChosenClass.Orders .Single(x => x.OrderTID == OIDs.OrderID); } if (OIDs.FamilyID != null) { viewModel.ChosenFamily = viewModel.ChosenOrder.Families .Single(x => x.FamilyTID == OIDs.FamilyID); } if (OIDs.GenusID != null) { viewModel.ChosenGenus = viewModel.ChosenFamily.Genusses .Single(x => x.GenusTID == OIDs.GenusID); } if (OIDs.SpeciesID != null) { viewModel.ChosenSpecies = viewModel.ChosenGenus.Species .Single(x => x.SpeciesTID == OIDs.SpeciesID); await _context.Entry(viewModel.ChosenSpecies) .Collection(x => x.Imgs).LoadAsync(); } return(viewModel); }