Exemplo n.º 1
0
        public async Task <IHttpActionResult> Post([FromBody] Location location)
        {
            _db.Locations.Add(location);
            await _db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = location.Id }, location));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Post([FromBody] Manager manager)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(HttpStatusCodeExtensions.UnprocessableEntity));
            }

            var managerExists = await _db.Managers.AnyAsync(m => m.Profile.Email == manager.Profile.Email);

            if (managerExists)
            {
                return(Conflict());
            }

            var existingProfile = await _db.Profiles
                                  .Where(m => m.Email == manager.Profile.Email)
                                  .SingleOrDefaultAsync();

            _db.Managers.Add(manager);
            if (existingProfile != null)
            {
                manager.Profile.Id     = existingProfile.Id;
                manager.Profile.UserId = await _db.Users
                                         .Where(user => user.Email == manager.Profile.Email)
                                         .Select(user => user.Id)
                                         .SingleOrDefaultAsync() ?? existingProfile.UserId;

                _db.Entry(manager.Profile).State = EntityState.Modified;
            }

            await _db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = manager.Id }, manager));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> Post([FromBody] League league)
        {
            _db.Leagues.Add(league);
            await _db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = league.Id }, league));
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> Post(Booking booking)
        {
            _db.Bookings.Add(booking);
            await _db.SaveChangesAsync();

            return(CreatedAtRoute("GetSingleBooking", new { id = booking.Id }, booking));
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> PostTeamPlayer(int id, TeamPlayerBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var player = await _db.Players
                         .Include(p => p.Teams)
                         .Include(p => p.Profile)
                         .Where(p =>
                                p.Profile.FirstName == model.FirstName &&
                                p.Profile.LastName == model.LastName
                                )
                         .FirstOrDefaultAsync();

            if (player == null)
            {
                var profile = _db.Profiles.Add(new Profile {
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                });

                player = _db.Players.Add(new Player {
                    Profile = profile
                });

                await _db.SaveChangesAsync();
            }

            if (player.Teams.Any(t => t.Id == id))
            {
                return(BadRequest());
            }

            var team = await _db.Teams.FindAsync(id);

            player.Teams.Add(team);

            await _db.SaveChangesAsync();

            return(Ok(player));
        }
Exemplo n.º 6
0
        public async Task <IHttpActionResult> PutResult(int id, [FromBody] Game model)
        {
            var game = await _db.Games
                       .WithDetails()
                       .SingleOrDefaultAsync(g => g.Id == id);

            if (game == null)
            {
                return(NotFound());
            }

            game.IncludeInStandings = model.IncludeInStandings;
            game.WasCancelled       = model.WasCancelled;
            game.WasForfeited       = model.WasForfeited;
            game.ForfeitingTeamId   = model.ForfeitingTeamId;

            await _db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> Post([FromBody] AddGoalBindingModel model)
        {
            var game = await _db.Games
                       .WithDetails()
                       .SingleOrDefaultAsync(g => g.Id == model.GameId);

            if (game == null)
            {
                return(NotFound());
            }

            var newGoal = new Goal {
                PlayerId = model.PlayerId,
                Count    = model.Count
            };

            game.Goals.Add(newGoal);

            await _db.SaveChangesAsync();

            return(CreatedAtRoute("GetPlayerGoals", new { id = model.PlayerId }, newGoal));
        }
Exemplo n.º 8
0
        public async Task<IHttpActionResult> Post([FromBody] Division division) {
            _db.Divisions.Add(division);
            await _db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = division.Id }, division);
        }