Example #1
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)));
     }
 }
Example #2
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)));
     }
 }
Example #3
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)));
     }
 }
Example #4
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)));
     }
 }
Example #5
0
 public async Task <IActionResult> Add([FromBody] Step step)
 {
     try
     {
         return(this.Ok(await _repository.Add(step)));
     }
     catch (Exception e)
     {
         return(this.Ok(TranslateError.Convert(e)));
     }
 }
Example #6
0
 public TranslateException(string message, IRestResponse response) : base(message)
 {
     this.Response = response;
     try
     {
         this.error = CommonHelper.Deserialize <TranslateError>(response.Content);
     }
     catch
     {
         this.error = null;
     }
 }
Example #7
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)));
     }
 }
Example #8
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)));
     }
 }
Example #9
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));
            }
        }
Example #10
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));
     }
 }
Example #11
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));
     }
 }
Example #12
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));
     }
 }
Example #13
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));
     }
 }
Example #14
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));
            }
        }
Example #15
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));
            }
        }
Example #16
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));
            }
        }
Example #17
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));
            }
        }
Example #18
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));
            }
        }
Example #19
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));
            }
        }
Example #20
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));
            }
        }
Example #21
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));
            }
        }
Example #22
0
        /// <summary>
        /// Method to Add a list of TeamPlayer passed in the parameters to the database
        /// </summary>
        /// <param name="teamPlayers">List of object TeamPlayer to Add</param>
        public async Task <ApiResponse> AddRange(List <TeamPlayer> teamPlayers)
        {
            try
            {
                await _context.Teamplayers.AddRangeAsync(teamPlayers);

                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Add, Response = teamPlayers
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Example #23
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));
            }
        }
Example #24
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));
            }
        }
Example #25
0
        /// <summary>
        /// Method to Add the Game passed in the parameters to the database
        /// </summary>
        /// <param name="game">Object Game to Add</param>
        public async Task <ApiResponse> Add(Game game)
        {
            try
            {
                if (!await _teamBusiness.DuplicatePlayer(game.Plays.ToList()))
                {
                    var newGame = _gameBusiness.SeparatePlay(game);
                    await _context.Games.AddAsync(newGame);

                    await _context.SaveChangesAsync();

                    var reponse = await _playBusiness.SetUp(game.Plays.ToList(), newGame.Id);

                    if (reponse.Status == ApiStatus.Ok)
                    {
                        var reponseGenerate = await _gameBusiness.GenerateTeamRoute(game, newGame.Id);

                        if (reponseGenerate.Status == ApiStatus.Ok)
                        {
                            return new ApiResponse {
                                       Status = ApiStatus.Ok, Message = ApiAction.Update, Response = await this.Find(newGame.Id)
                            }
                        }
                        ;
                        else
                        {
                            return(reponseGenerate);
                        }
                    }
                    else
                    {
                        return(reponse);
                    }
                }
                else
                {
                    return(new ApiResponse {
                        Status = ApiStatus.CantAdd, Message = "Impossible, un joueur est dans plusieurs équipes selectionnées !"
                    });
                }
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Example #26
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));
            }
        }
Example #27
0
        /// <summary>
        /// Method to change the capitaine if the player was the capitaine in his team
        /// </summary>
        /// <param name="idPlayer">Id of the player</param>
        public async Task <ApiResponse> ChangeCapitaine(int idPlayer)
        {
            try
            {
                await _context.Teams.Where(x => x.IdCaptain == idPlayer).Include(x => x.TeamPlayers).ForEachAsync(x => {
                    x.IdCaptain = x.TeamPlayers.FirstOrDefault(c => c.IdPlayer != idPlayer).IdPlayer;
                });

                _context.SaveChanges();
                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = ApiAction.Delete
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Example #28
0
        /// <summary>
        /// Method that will Update the TeamRoute passed in the parameters to the database
        /// </summary>
        /// <param name="teamRoute">Object TeamRoute to Update</param>
        public async Task <ApiResponse> Update(TeamRoute teamRoute, bool validate)
        {
            try
            {
                var oldteamRoute = await _context.Teamroutes.FirstOrDefaultAsync(rt => rt.Id == teamRoute.Id);

                oldteamRoute.ValidationDate = teamRoute.ValidationDate;
                oldteamRoute.Validate       = teamRoute.Validate;
                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = (validate) ? "Validation effectuée avec succées !" : "Reject effectué avec succées !", Response = teamRoute
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Example #29
0
        /// <summary>
        /// Method to analyze picture and add some tag
        /// </summary>
        /// <param name="image64">Image convert string 64</param>
        /// <param name="fileName">Name of file</param>
        /// <returns></returns>
        public async Task <ApiResponse> Analyze(string image64, int idStep)
        {
            try
            {
                var tags = await _vision.GetTags(image64, _fileExtension.GetExtension(image64.Substring(0, 50)));

                var listAlreadyCreatedTag = await _context.Tags.Where(t => tags.Select(tag => tag.Description).Contains(t.Name)).ToListAsync();

                var newTags     = tags.Where(t => !listAlreadyCreatedTag.Select(a => a.Name).Contains(t.Description)).ToList();
                var listNewTags = newTags.Select(t => new Tag {
                    Id = 0, Name = t.Description, Description = t.Description, Color = null
                }).ToList();
                await _context.Tags.AddRangeAsync(listNewTags);

                await _context.SaveChangesAsync();

                List <StepTag> stepTags = new List <StepTag>();
                if (listNewTags.Count() != 0)
                {
                    stepTags.AddRange(listNewTags.Select(t => new StepTag {
                        IdStep = idStep, IdTag = t.Id
                    }).ToList());
                }
                if (listAlreadyCreatedTag.Count() != 0)
                {
                    stepTags.AddRange(listAlreadyCreatedTag.Select(t => new StepTag {
                        IdStep = idStep, IdTag = t.Id
                    }).ToList());
                }

                await _stepAnalyseBusiness.AddRange(stepTags, await _vision.GetWhat(image64, _fileExtension.GetExtension(image64.Substring(0, 50)), idStep));

                await _context.SaveChangesAsync();

                return(new ApiResponse {
                    Status = ApiStatus.Ok, Message = "Image analyzed"
                });
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Example #30
0
        /// <summary>
        /// Method to Add a list of StepTag passed in the parameters to the database
        /// </summary>
        /// <param name="stepTags">List of object StepTag to Add</param>
        /// <param name="stepValidations">List of object StepValidation to Add</param>
        public async Task <ApiResponse> AddRange(List <StepTag> stepTags, List <StepValidation> stepValidations)
        {
            try
            {
                await _context.Steptags.AddRangeAsync(stepTags);

                await _context.StepValidations.AddRangeAsync(stepValidations);

                await _context.SaveChangesAsync();

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