public async Task <IActionResult> Edit(string id, [Bind("Abbrev,Nation,Tier,ShipName,Survivability,Aircraft,Artillery,AaDefense,Maneuverability,Concealment")] AircraftCarriers aircraftCarriers) { if (id != aircraftCarriers.Abbrev) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(aircraftCarriers); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AircraftCarriersExists(aircraftCarriers.Abbrev)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Abbrev"] = new SelectList(_context.ShipClasses, "Abbreviation", "Abbreviation", aircraftCarriers.Abbrev); ViewData["Nation"] = new SelectList(_context.ShipNations, "NationAbbrev", "NationAbbrev", aircraftCarriers.Nation); return(View(aircraftCarriers)); }
public async Task <IActionResult> Create([Bind("Abbrev,Nation,Tier,ShipName,Survivability,Aircraft,Artillery,AaDefense,Maneuverability,Concealment")] AircraftCarriers aircraftCarriers) { if (ModelState.IsValid) { _context.Add(aircraftCarriers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Abbrev"] = new SelectList(_context.ShipClasses, "Abbreviation", "Abbreviation", aircraftCarriers.Abbrev); ViewData["Nation"] = new SelectList(_context.ShipNations, "NationAbbrev", "NationAbbrev", aircraftCarriers.Nation); return(View(aircraftCarriers)); }
internal static void AddSh(object Item, string SType) { using (var db = new DatabaseContext()) { switch (SType) { case "AircraftCarriers": AircraftCarriers tempAC = new AircraftCarriers(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempAC, x.GetValue(Item)); } db.Ships.Add(tempAC); break; case "AmphibiousWarfare": AmphibiousWarfare tempAW = new AmphibiousWarfare(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempAW, x.GetValue(Item)); } db.Ships.Add(tempAW); break; case "Cruisers": Cruisers tempC = new Cruisers(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempC, x.GetValue(Item)); } db.Ships.Add(tempC); break; case "Destroyers": Destroyers tempD = new Destroyers(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempD, x.GetValue(Item)); } db.Ships.Add(tempD); break; case "Frigates": Frigates tempF = new Frigates(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempF, x.GetValue(Item)); } db.Ships.Add(tempF); break; case "Submarines": Submarines tempS = new Submarines(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempS, x.GetValue(Item)); } db.Ships.Add(tempS); break; } db.SaveChanges(); } }