示例#1
0
        public IHttpActionResult Post(GameNightCreate gameNight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateGameNightService();

            if (!service.CreateGameTime(gameNight))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
示例#2
0
        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));
        }
示例#3
0
        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);
            }
        }