public bool CreateBird(BirdCreate model) { var entity = new Bird() { Name = model.Name, MainColor = model.MainColor, SecondColor = model.SecondColor }; var sighting = new Sighting() { SpotterID = _userId.ToString(), Bird = entity, TimeSeen = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Birds.Add(entity); ctx.Sightings.Add(sighting); return(ctx.SaveChanges() == 2); } }
public ActionResult Create(BirdCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateBirdService(); if (service.CreateBird(model)) { TempData["SaveResult"] = "The bird was spotted!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "The bird could not be added."); return(View(model)); }