示例#1
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));
            }
        }