Exemplo n.º 1
0
        public ActionResult Create(Game game)
        {
            if (ModelState.IsValid)
            {
                db.Games.Add(game);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.LocationId = new SelectList(db.Locations, "Id", "Name", game.LocationId);
            ViewBag.BallerId = new SelectList(db.Ballers, "Id", "UserName", game.CreatorId);
            ViewBag.SportId = new SelectList(db.Sports, "Id", "Name", game.SportId);
            return View(game);
        }
Exemplo n.º 2
0
        public HttpResponseMessage PutGame(int id, Game game)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != game.Id)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(game).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Exemplo n.º 3
0
        public IHttpActionResult PostGame(Game game)
        {
            if (ModelState.IsValid)
            {
                game.CreatorId = db.Ballers
                                .Where(x => x.UserName == User.Identity.Name)
                                .Select(x => x.Id).FirstOrDefault();

                db.Games.Add(game);
                db.SaveChanges();

                // HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, game);
                //response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = game.Id }));
                return Created(Url.Link("DefaultApi", new { id = game.Id } ),game);
            }
            else
            {
               // return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                return BadRequest(ModelState);
            }
        }