public async Task <IActionResult> Create([Bind("RelationshipID,Character1ID,Character2ID,RelationshipTypeID,Details")] Relationship Relationship) { bool related = false; var context = _context.Relationships.Where(c => c.Character1ID == Relationship.Character1ID).ToList(); foreach (var c in context) { if (c.Character2ID == Relationship.Character2ID) { related = true; break; } } if (ModelState.IsValid && !related) { await UpdateRelationsAsync(Relationship); _context.Add(Relationship); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.related = true; ViewData["RelationshipTypeID"] = new SelectList(_context.RelationshipTypes, "RelationshipTypeID", "Description", Relationship.RelationshipTypeID); ViewBag.char1 = new SelectList(_context.Characters.Where(c => c.CharacterID == Relationship.Character1ID), "CharacterID", "Name"); ViewBag.chars = new SelectList(_context.Characters.Where(c => c.CharacterID != Relationship.Character1ID), "CharacterID", "Name"); return(View()); }
public async Task EnsureSeedDataAsync() { if (await _userManager.FindByEmailAsync("*****@*****.**") == null) { var user = new WorldUser() { UserName = "******", Email = "*****@*****.**" }; await _userManager.CreateAsync(user, "P@ssw0rd!"); } // Seed some data if none exist. if (!_context.Trips.Any()) { var usTrip = new Trip { Name = "US Trip", Created = DateTime.Now, UserName = string.Empty, Stops = new List <Stop> { new Stop { Name = "Atlanta, GA", Arrival = new DateTime(2014, 2, 3), Latitude = 33.748995, Longitude = -84.387982, Order = 0 }, new Stop { Name = "New York, NY", Arrival = new DateTime(2015, 6, 28), Latitude = 40.712784, Longitude = -74.005941, Order = 1 } } }; var worldTrip = new Trip { Name = "World Trip", Created = DateTime.Now, UserName = string.Empty, Stops = new List <Stop> { new Stop { Name = "Penang, MY", Arrival = new DateTime(2015, 12, 4), Latitude = 33.748995, Longitude = -84.387982, Order = 0 }, } }; _context.Add(usTrip); _context.AddRange(usTrip.Stops); _context.Add(worldTrip); _context.AddRange(worldTrip.Stops); _context.SaveChanges(); } }
public async Task <IActionResult> Create([Bind("Name,CharacterID,WorldID,LocationID,Summary")] Character character) { ViewBag.data = null; if (ModelState.IsValid) { var location = await _context.Locations.Include(l => l.World).FirstOrDefaultAsync(m => m.LocationID == character.LocationID); //if (character.LocationID != null) // { if (character.LocationID != null && character.WorldID != location.WorldID) { ViewData["LocationID"] = new SelectList(_context.Locations, "LocationID", "Name", character.LocationID); ViewData["WorldID"] = new SelectList(_context.Worlds, "WorldID", "Name", character.WorldID); ViewBag.location = location; return(View(character)); } // } _context.Add(character); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LocationID"] = new SelectList(_context.Locations, "LocationID", "Name", character.LocationID); ViewData["WorldID"] = new SelectList(_context.Worlds, "WorldID", "Name", character.WorldID); return(View(character)); }
public async Task <IActionResult> Create([Bind("Name,Summary,WorldID")] World world) { if (ModelState.IsValid && world.Name != null) { _context.Add(world); await _context.SaveChangesAsync(); return(RedirectToAction("World", "Worlds", new { id = world.WorldID })); } return(View(world)); }
public async Task <IActionResult> Create([Bind("LoreID,WorldID,Title,Details")] Lore lore) { if (ModelState.IsValid && lore.Title != null) { _context.Add(lore); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["WorldID"] = new SelectList(_context.Worlds, "WorldID", "Name", lore.WorldID); return(View(lore)); }
public async Task <IActionResult> Create([Bind("LocationID,WorldID,Name,Summary")] Location location) { if (ModelState.IsValid && location.Name != null) { _context.Add(location); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["WorldID"] = new SelectList(_context.Worlds, "WorldID", "Name", location.WorldID); return(View(location)); }
//[Authorize] public void AddTrip(Trip tripObject) { _context.Add(tripObject); }
public void AddTrip(Trip newTrip) { _context.Add(newTrip); }
// Pushing a new obj into a context, not saving into DB public void AddTrip(Trip trip) { _context.Add(trip); }