public IHttpActionResult Post(GameNightCreate gameNight) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateGameNightService(); if (!service.CreateGameTime(gameNight)) { return(InternalServerError()); } return(Ok()); }
public ActionResult Create(GameNightCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateGameNightService(); if (service.CreateGameTime(model)) { TempData["SaveResult"] = "Your game was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Game could not be created."); return(View(model)); }
public bool CreateGameTime(GameNightCreate model) { var entity = new GameTime() { GameId = model.GameId, OwnerId = _userId, DateTime = model.DateTime, Location = model.Location, NoobsAllowed = model.NoobsAllowed, Description = model.Description, TutorialVideo = model.TutorialVideo, GamerTag = model.GamerTag }; using (var ctx = new ApplicationDbContext()) { ctx.GameTimes.Add(entity); return(ctx.SaveChanges() == 1); } }