Esempio n. 1
0
        /// <summary>
        /// Generate team route differently and random
        /// </summary>
        /// <param name="game">Object game</param>
        /// <param name="idGame">Id of the game</param>
        public async Task <ApiResponse> GenerateTeamRoute(Game game, int idGame)
        {
            try
            {
                var nbOrder    = new List <int>();
                var listIdStep = game.Route.RouteSteps.ToList().Select(rs =>
                {
                    nbOrder.Add(nbOrder.Count + 1);
                    return(rs.IdStep);
                }).ToList();
                var listIdTeam    = game.Plays.ToList().Select(p => p.IdTeam).ToList();
                var listOrder     = nbOrder.Shuffle(game.Plays.Count());
                var listTeamRoute = new List <TeamRoute>();
                await _context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.TEAMROUTE ON");

                foreach (var l in listOrder)
                {
                    foreach (var order in l)
                    {
                        await _context.Database.ExecuteSqlInterpolatedAsync($"INSERT INTO [dbo].[TEAMROUTE] ([TeamRoute_fk_Game_Id], [TeamRoute_fk_Team_Id], [TeamRoute_fk_Route_Id], [TeamRoute_fk_Step_Id], [TeamRoute_StepOrder], [TeamRoute_Validate]) VALUES ({idGame}, {listIdTeam[listOrder.IndexOf(l)]}, {game.IdRoute}, {listIdStep[l.IndexOf(order)]}, {order}, {false})");
                    }
                }
                await _context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.TEAMROUTE OFF");

                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Add
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Method to Delete from the database the Transport passed in the parameters
        /// </summary>
        /// <param name="idTransport">Object Transport to Delete</param>
        public async Task <ApiResponse> Delete(int idTransport)
        {
            try
            {
                if (!(await _context.Games.AnyAsync(t => t.IdTransport == idTransport)))
                {
                    _context.Transports.Remove(await _context.Transports.Where(t => t.Id == idTransport).FirstOrDefaultAsync());
                    await _context.SaveChangesAsync();

                    return(new ApiResponse {
                        Status = ApiStatus.Ok, Message = ApiAction.Delete
                    });
                }
                else
                {
                    return(new ApiResponse {
                        Status = ApiStatus.CantDelete, Message = "Ce transport est déjà utilisé dans un jeu !"
                    });
                }
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Method to Add the team passed in the parameters to the database
        /// </summary>
        /// <param name="step">Object Team to Add</param>
        public async Task <ApiResponse> Add(Team team)
        {
            try
            {
                var newTeam = _teamBusiness.SeparateTeam(team);
                await _context.Teams.AddAsync(newTeam);

                await _context.SaveChangesAsync();

                team.Id = newTeam.Id;
                var response = await _teamPlayerBusiness.SetUp(team.TeamPlayers.ToList(), team.Id);

                if (response.Status == ApiStatus.Ok)
                {
                    return(new ApiResponse {
                        Status = ApiStatus.Ok, Message = ApiAction.Add, Response = await this.Find(team.Id)
                    });
                }
                else
                {
                    return(response);
                }
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Method to Add the Player passed in the parameters to the database
        /// </summary>
        /// <param name="game">Object Player to Add</param>
        public async Task <ApiResponse> Add(Player player)
        {
            try
            {
                if (!await _playerBusiness.Check(player))
                {
                    player.Picture = await _imageBusiness.UploadImage(player.ImageBase64, $"{player.FirstName}-{player.LastName}-{player.Login}-{DateTime.Now.ToString("yyyyMMddHHmmss")}");

                    player.Password = _cryption.Encrypt(player.Password);
                    await _context.Players.AddAsync(player);

                    await _context.SaveChangesAsync();

                    return(new ApiResponse {
                        Status = ApiStatus.Ok, Message = ApiAction.Add, Response = player
                    });
                }
                else
                {
                    return(new ApiResponse {
                        Status = ApiStatus.CantDelete, Message = "Le pseudo et l'e-mail doivent être uniques."
                    });
                }
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Method to Delete from the database the Game passed in the parameters
        /// </summary>
        /// <param name="game">Object Game to Delete</param>
        public async Task <ApiResponse> Delete(int id)
        {
            try
            {
                var game = await _context.Games.FindAsync(id);

                if (_gameBusiness.IsGameInProgress(game) == false)
                {
                    await _gameBusiness.DeleteAllTeams(game);

                    _context.Games.Remove(await _context.Games.FindAsync(id));
                    _context.SaveChanges();
                    return(new ApiResponse {
                        Status = ApiStatus.Ok, Message = ApiAction.Delete
                    });
                }
                else
                {
                    return(new ApiResponse {
                        Status = ApiStatus.CantDelete, Message = "Ce jeu est en cours ou a déjà été joué."
                    });
                }
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 6
0
 public async Task <IActionResult> Post([FromBody] Play play)
 {
     try
     {
         return(this.Ok(await this._repository.Add(play)));
     }
     catch (Exception e)
     {
         return(this.StatusCode(500, TranslateError.Convert(e)));
     }
 }
Esempio n. 7
0
 public async Task <IActionResult> Check([FromBody] Validate validate)
 {
     try
     {
         return(this.Ok(await this._repository.Check(validate)));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Esempio n. 8
0
 public async Task <IActionResult> test()
 {
     try
     {
         return(this.Ok(await this._repository.Test("https://00e9e64bacf823a5e9fa6c8c8892d4084caa844c0aac596752-apidata.googleusercontent.com/download/storage/v1/b/dijiwalk-test/o/MicrosoftTeams-image.png?qk=AD5uMEu6C7GAVBlOKnJNU6K9RXnO2G8PR3ImoTnf0NMLjtMuIIraanKKz63_vzyr0AB9mb8YRoPt193f2IyggFlrViVAJpupVYirHSbDwBO9nRFGRR0VfBes8uDv1RlKu8d4ZKylFlhuBNwXYOLfYJzZvUCaPqegK3p0o0pM-dBa2tAWcaCzjSX21fJPZr1BDByaJDeJUX7pirTQExsYRmUzTAwU3QrXvLXfyb71Pz7iK1WJ1JKNMPUzIUnL2gYqi1TbbZIbTHMSJg_SZGQdBvcn2SOwYwhksOZ5rko_zzKsT2RGiNPxxZ1tlWqqHqtvbzxiIFstRe6uycoVm3gxuBi3t7AeEDtjyhTofmzGc1AiDUCMCbLC4XQM_3wdYV4IOB8iMJXII8D1HKZrSHvGDNlrYYgq4FX6ezqrE-FSDHII-fWy6EJKZ-ILipXd2jAH1144EDg5UTdCvVlL-WBe6-u0C4FwYffb9o5cbiFZxmVVue6tG-4w-aVnqOFB0m169mtbd3foXfXxP55U6r7kBBI3t0Qnt6hdSWguYpwLIy7jCVUL05-4cayIErL39o-1oeL-fVp9z2fCKWn1E0fYpgK4oR3gEofpXJQrF76khFJpsqBgC7yCdeOZuvinTLUO5pf-hEcUUl4_x1L5in4MyWuabNlVLTkvlu-gXrgJrd9F7yYJbR-zQiRyZsPIeZUrjHwI7nP9cO41syEmY7drTCd9QwREStyi-zete2lC-JDVaeLL8M7SD2gbLQ_MWsPMkOm1lbcF-WekWf8zc1i7K6uKxrs05tXTcYwWg3mUDQbYu6JXFNnAsNA")));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Esempio n. 9
0
 public async Task <IActionResult> Add([FromBody] Team team)
 {
     try
     {
         return(this.Ok(await _repository.Add(team)));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Esempio n. 10
0
 public async Task <IActionResult> Post([FromBody] Player player)
 {
     try
     {
         return(this.Ok(await _repository.Add(player)));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Esempio n. 11
0
 public async Task <IActionResult> Reject(TeamRoute teamRoute)
 {
     try
     {
         return(this.Ok(await _repository.Update(teamRoute, false)));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Esempio n. 12
0
 public async Task <IActionResult> Delete(int id)
 {
     try
     {
         return(this.Ok(await this._repository.Delete(id)));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Esempio n. 13
0
 public async Task <IActionResult> Update(int id, Player player)
 {
     try
     {
         player.Id = id;
         return(this.Ok(await _repository.Update(player)));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Esempio n. 14
0
 public async Task <IActionResult> Update(int id, Team team)
 {
     try
     {
         team.Id = id;
         return(this.Ok(await _repository.Update(team)));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Method that will Update the Team passed in the parameters to the database
        /// </summary>
        /// <param name="team">Object Team to Update</param>
        public async Task <ApiResponse> Update(Team team)
        {
            try
            {
                if (!await _teamBusiness.ContainsTeams(team.Id))
                {
                    _context.Teams.Update(_teamBusiness.SeparateTeam(team));
                    await _context.SaveChangesAsync();

                    // Récupérer tous les id actuels des participants de la team dans la DB
                    var currentIdParticipants = await _context.Teamplayers.Where(p => p.IdTeam == team.Id).Select(p => p.IdPlayer).ToListAsync();

                    // Récuperer tous les id des participants de la game envoyée en paramètre
                    var idParticipant = team.TeamPlayers.Select(p => p.IdPlayer).ToList();

                    // liste des id de la BDD qui ne sont pas dans les ID de l'update
                    var oldIdParticipant = currentIdParticipants.Where(p => !idParticipant.Contains(p)).ToList();

                    var responseDelete = await _teamPlayerBusiness.DeleteFromTeam(await _context.Teamplayers.Where(p => p.IdTeam == team.Id && oldIdParticipant.Contains(p.IdPlayer)).ToListAsync());

                    if (responseDelete.Status == ApiStatus.Ok)
                    {
                        var responseTeamPlayerAdd = await _teamPlayerBusiness.SetUp(team.TeamPlayers.Where(p => !currentIdParticipants.Contains(p.IdPlayer)).ToList(), team.Id);

                        if (responseTeamPlayerAdd.Status == ApiStatus.Ok)
                        {
                            return(new ApiResponse {
                                Status = ApiStatus.Ok, Message = ApiAction.Update, Response = await this.Find(team.Id)
                            });
                        }
                        else
                        {
                            return(responseTeamPlayerAdd);
                        }
                    }
                    else
                    {
                        return(responseDelete);
                    }
                }
                else
                {
                    return(new ApiResponse {
                        Status = ApiStatus.CantUpdate, Message = "Impossible de mettre à jour une équipe qui a déjà jouée !"
                    });
                }
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Method to Delete from the database the TeamAnswer passed in the parameters
 /// </summary>
 /// <param name="teamAnswer">Object TeamAnswer to Delete</param>
 public async Task <ApiResponse> Delete(int idTeamAnswer)
 {
     try
     {
         _context.Teamanswers.Remove(await _context.Teamanswers.FindAsync(idTeamAnswer));
         _context.SaveChanges();
         return(new ApiResponse {
             Status = ApiStatus.Ok, Message = ApiAction.Delete
         });
     }
     catch (Exception e)
     {
         return(TranslateError.Convert(e));
     }
 }
Esempio n. 17
0
 /// <summary>
 /// Method to Delete all message of a player
 /// </summary>
 /// <param name="idPlayer">Id of a player</param>
 public async Task <ApiResponse> DeleteAllFromPlayer(int idPlayer)
 {
     try
     {
         _context.Messages.RemoveRange(await _context.Messages.Where(m => m.IdPlayer == idPlayer).ToListAsync());
         _context.SaveChanges();
         return(new ApiResponse {
             Status = ApiStatus.Ok, Message = ApiAction.Delete
         });
     }
     catch (Exception e)
     {
         return(TranslateError.Convert(e));
     }
 }
Esempio n. 18
0
 /// <summary>
 /// Method to Delete all team route with route id
 /// </summary>
 /// <param name="idRoute">id of the route</param>
 public async Task <ApiResponse> DeleteTeamRoutesFromRoute(int idRoute)
 {
     try
     {
         _context.Teamroutes.RemoveRange(await _context.Teamroutes.Where(x => x.IdRoute == idRoute).ToListAsync());
         _context.SaveChanges();
         return(new ApiResponse {
             Status = ApiStatus.Ok, Message = ApiAction.Delete
         });
     }
     catch (Exception e)
     {
         return(TranslateError.Convert(e));
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Method to Delete from the database the Play passed in the parameters
 /// </summary>
 /// <param name="play">Object Play to Delete</param>
 public async Task <ApiResponse> Delete(int idGame, int idTeam)
 {
     try
     {
         _context.Plays.Remove(await _context.Plays.FirstOrDefaultAsync(p => p.IdGame == idGame && p.IdTeam == idTeam));
         _context.SaveChanges();
         return(new ApiResponse {
             Status = ApiStatus.Ok, Message = ApiAction.Delete
         });
     }
     catch (Exception e)
     {
         return(TranslateError.Convert(e));
     }
 }
Esempio n. 20
0
        /// <summary>
        /// Method that will Update the Transport passed in the parameters to the database
        /// </summary>
        /// <param name="transport">Object Transport to Update</param>
        public async Task <ApiResponse> Update(Transport transport)
        {
            try
            {
                _context.Transports.Update(transport);
                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Update, Response = transport
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Method to Add the Play passed in the parameters to the database
        /// </summary>
        /// <param name="play">Object Play to Add</param>
        public async Task <ApiResponse> Add(Play play)
        {
            try
            {
                await _context.Plays.AddAsync(play);

                _context.SaveChanges();
                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Add, Response = play
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Method to Delete all link between question and answer
        /// </summary>
        /// <param name="idTrial">Id of the trial</param>
        public async Task <ApiResponse> DeleteAllFromTrial(int idTrial)
        {
            try
            {
                _context.Answers.RemoveRange(await _context.Answers.Where(x => x.IdTrial == idTrial).ToListAsync());
                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Delete
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Method to Delete all plays
        /// </summary>
        /// <param name="plays">List of plays to delete</param>
        public async Task <ApiResponse> DeleteFromGame(List <Play> plays)
        {
            try
            {
                _context.Plays.RemoveRange(plays);
                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Delete
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Method to Delete all link between step and mission
        /// </summary>
        /// <param name="missionToDelete">List of mission to delete</param>
        public async Task <ApiResponse> DeleteNotFromStep(List <Mission> missionToDelete)
        {
            try
            {
                _context.Missions.RemoveRange(missionToDelete);
                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Delete
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Method to Delete all TeamPlayer
        /// </summary>
        /// <param name="teamPlayer">List of TeamPlayer to delete</param>
        public async Task <ApiResponse> DeleteFromTeam(List <TeamPlayer> teamPlayer)
        {
            try
            {
                _context.Teamplayers.RemoveRange(teamPlayer);
                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Delete
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 26
0
        public async Task <ApiResponse> DeleteAllTeamsRoute(int gameId)
        {
            try
            {
                _context.Teamroutes.RemoveRange(await _context.Teamroutes.Where(p => p.IdGame == gameId).ToListAsync());
                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Delete
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Method to add answer of trial of duplicate mission
        /// </summary>
        /// <param name="answers">List of new answers</param>
        public async Task <ApiResponse> AddFromNewTrialFromMissionFromStep(List <Answer> answers)
        {
            try
            {
                await _context.Answers.AddRangeAsync(answers);

                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Add
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Method to Add the Tag passed in the parameters to the database
        /// </summary>
        /// <param name="tag">Object Tag to Add</param>
        public async Task <ApiResponse> Add(Tag tag)
        {
            try
            {
                await _context.Tags.AddAsync(tag);

                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Add, Response = tag
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Method to Delete all step analyze
        /// </summary>
        /// <param name="idStep">Id of step</param>
        public async Task <ApiResponse> DeleteFromStep(int idStep)
        {
            try
            {
                _context.Steptags.RemoveRange(await _context.Steptags.Where(st => st.IdStep == idStep).ToListAsync());
                _context.StepValidations.RemoveRange(await _context.StepValidations.Where(sv => sv.IdStep == idStep).ToListAsync());
                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Delete
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Method to Add a list of routestep passed in the parameters to the database
        /// </summary>
        /// <param name="routeSteps">List of object RouteStep to Add</param>
        public async Task <ApiResponse> AddRange(List <RouteStep> routeSteps)
        {
            try
            {
                await _context.Routesteps.AddRangeAsync(routeSteps);

                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Add, Response = routeSteps
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }