{ //CREATE public IHttpActionResult Post(AttractionCreate note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateAttractionService(); if (!service.CreateAttraction(note)) { return(InternalServerError()); } return(Ok()); }
//CREATE ATTRACTION public bool CreateAttraction(AttractionCreate model) { Attraction attraction = new Attraction { Name = model.Name, Type = model.Type, AttractionRating = model.AttractionRating, AttractionLocation = model.AttractionLocation }; using (ApplicationDbContext ctx = new ApplicationDbContext()) { ctx.Attractions.Add(attraction); return(ctx.SaveChanges() == 1); } }
public bool CreateAttraction(AttractionCreate model) { var entity = new Attraction { ZooId = model.ZooId, Animals = model.Animals, Experiences = model.Experiences, HasAquaticExhibit = model.HasAquaticExhibit, HasGarden = model.HasGarden, SeasonalAttractions = model.SeasonalAttractions }; using (var ctx = new ApplicationDbContext()) { ctx.Attractions.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateAttraction(AttractionCreate model) { var entity = new Attraction() { OwnerID = _userID, AttractionName = model.AttractionName, ParkID = model.ParkID, AttractionTypeID = model.AttractionTypeID, AttractionType = model.AttractionType, AttractionRating = model.AttractionRating, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Attractions.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(AttractionCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateAttractionService(); if (service.CreateAttraction(model)) { TempData["SaveResult"] = "Your Attraction was created."; return(RedirectToAction("Index")); } ; ViewBag.ParkID = new SelectList(db.Parks, "ParkID", "ParkName"); ViewBag.AttractionTypeID = new SelectList(db.AttractionTypes, "AttractionTypeID", "AttractionTypeName"); ModelState.AddModelError("", "Attraction could not be created."); return(View(model)); }