Пример #1
0
        public async Task <ActionResult <Models.Team> > PutTeam(long id, Team team)
        {
            bool isUnique = await _context.IsUnique(team.name, id);

            if (!isUnique)
            {
                return(ValidationProblem("Name must be unique"));
            }

            var originalTask = await _context.GetTeam(id);

            team.id   = id;
            team.date = originalTask.date;
            team._id  = originalTask._id;

            await _context.Update(team);

            try
            {
                await _context.SaveChangesAsync();

                return(team);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeamExists(id))
                {
                    return(ValidationProblem());
                }
                else
                {
                    throw;
                }
            }
        }
        public async Task <ActionResult <Team> > PostTeam(Team team)
        {
            _context.Teams.Add(team);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTeam), new { id = team.Id }, team));
        }
Пример #3
0
        public async Task <IActionResult> PutTeam(long id, Team team)
        {
            if (id != team.Id)
            {
                return(BadRequest());
            }

            _context.Entry(team).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeamExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <Players> Add(Players player)
        {
            await _teamContext.Players.AddAsync(player);

            await _teamContext.SaveChangesAsync();

            return(player);
        }
Пример #5
0
        public async Task <PlayerStatuses> Add(PlayerStatuses playerStatus)
        {
            await _teamContext.PlayerStatuses.AddAsync(playerStatus);

            await _teamContext.SaveChangesAsync();

            return(playerStatus);
        }
        public async Task <Teams> Add(Teams team)
        {
            await _teamContext.Teams.AddAsync(team);

            await _teamContext.SaveChangesAsync();

            return(team);
        }
Пример #7
0
        public async Task <bool> SaveChangesAsync()
        {
            _logger.LogInformation($"Attempitng to save the changes in the context");

            // Only return success if at least one row was changed
            return((await _context.SaveChangesAsync()) > 0);
        }
Пример #8
0
 public static void Initialize(TeamContext context)
 {
     if (!context.TeamStates.Any())
     {
         context.TeamStates.AddRange(
             new TeamStates
         {
             TeamStateTitle = "pending"
         },
             new TeamStates
         {
             TeamStateTitle = "filled"
         },
             new TeamStates
         {
             TeamStateTitle = "active"
         }
             );
     }
     if (!context.PlayerStatuses.Any())
     {
         context.PlayerStatuses.AddRange(
             new PlayerStatuses
         {
             PlayerStatusTitle = "online"
         },
             new PlayerStatuses
         {
             PlayerStatusTitle = "offline"
         },
             new PlayerStatuses
         {
             PlayerStatusTitle = "blocked"
         }
             );
     }
     context.SaveChangesAsync();
 }