public async Task <IGamesResult> GetMyGames( IGamesRequest request, bool fullRecord = true) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new GamesResult(); try { if (await appsRepository.HasEntity(request.AppId)) { var response = await gamesRepository.GetMyGames( request.UserId, request.AppId, fullRecord); if (response.Success) { if (request.Paginator != null) { if (StaticDataHelpers.IsPageValid(request.Paginator, response.Objects)) { if (request.Paginator.SortBy == SortValue.NULL) { result.Games = response.Objects.ConvertAll(g => (IGame)g); } else if (request.Paginator.SortBy == SortValue.ID) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderBy(g => g.Id) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderByDescending(g => g.Id) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else if (request.Paginator.SortBy == SortValue.SCORE) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .Where(g => g.Score != 0 && g.Score != int.MaxValue && g.Score != 0 && !g.ContinueGame) .OrderByDescending(g => g.Score) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .Where(g => g.Score != 0 && g.Score != int.MaxValue && g.Score != 0 && !g.ContinueGame) .OrderBy(g => g.Score) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else if (request.Paginator.SortBy == SortValue.DATECREATED) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderBy(g => g.DateCreated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderByDescending(g => g.DateCreated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else if (request.Paginator.SortBy == SortValue.DATEUPDATED) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderBy(g => g.DateUpdated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderByDescending(g => g.DateUpdated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else { result.Success = false; result.Message = ServicesMesages.SortValueNotImplementedMessage; return(result); } } else { result.Success = false; result.Message = ServicesMesages.PageNotFoundMessage; return(result); } } else { result.Games = response.Objects.ConvertAll(g => (IGame)g); } if (fullRecord) { foreach (var game in result.Games) { foreach (var userRole in game.User.Roles) { userRole.Role.Users = null; } game.User.Apps = null; game.SudokuMatrix.Difficulty.Matrices = null; } } else { foreach (var game in result.Games) { game.User = null; game.SudokuMatrix = null; game.SudokuSolution = null; } } result.Success = response.Success; result.Message = GamesMessages.GamesFoundMessage; return(result); } else if (!response.Success && response.Exception != null) { result.Success = response.Success; result.Message = response.Exception.Message; return(result); } else { result.Success = false; result.Message = GamesMessages.GamesNotFoundMessage; return(result); } } else { result.Success = false; result.Message = AppsMessages.AppNotFoundMessage; return(result); } } catch (Exception exp) { result.Success = false; result.Message = exp.Message; return(result); } }
public async Task <ISolutionsResult> GetSolutions( IBaseRequest request, bool fullRecord = true) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new SolutionsResult(); try { var response = await solutionsRepository.GetAll(fullRecord); if (response.Success) { if (request.Paginator != null) { if (StaticDataHelpers.IsPageValid(request.Paginator, response.Objects)) { if (request.Paginator.SortBy == SortValue.NULL) { result.Solutions = response.Objects.ConvertAll(s => (ISudokuSolution)s); } else if (request.Paginator.SortBy == SortValue.ID) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Solutions.Add((ISudokuSolution)obj); } result.Solutions = result.Solutions .OrderBy(s => s.Id) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Solutions.Add((ISudokuSolution)obj); } result.Solutions = result.Solutions .OrderByDescending(s => s.Id) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else if (request.Paginator.SortBy == SortValue.DATECREATED) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Solutions.Add((ISudokuSolution)obj); } result.Solutions = result.Solutions .OrderBy(s => s.DateCreated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Solutions.Add((ISudokuSolution)obj); } result.Solutions = result.Solutions .OrderByDescending(s => s.DateCreated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else if (request.Paginator.SortBy == SortValue.DATEUPDATED) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Solutions.Add((ISudokuSolution)obj); } result.Solutions = result.Solutions .OrderBy(s => s.DateSolved) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Solutions.Add((ISudokuSolution)obj); } result.Solutions = result.Solutions .OrderByDescending(g => g.DateSolved) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else { result.Success = false; result.Message = ServicesMesages.SortValueNotImplementedMessage; return(result); } } else { result.Success = false; result.Message = ServicesMesages.PageNotFoundMessage; return(result); } } else { result.Solutions = response.Objects.ConvertAll(s => (ISudokuSolution)s); } if (fullRecord) { foreach (var solution in result.Solutions) { if (solution.Game != null) { solution.Game.SudokuMatrix.Difficulty.Matrices = null; } } } result.Success = response.Success; result.Message = SolutionsMessages.SolutionsFoundMessage; return(result); } else if (!response.Success && response.Exception != null) { result.Success = response.Success; result.Message = response.Exception.Message; return(result); } else { result.Success = false; result.Message = SolutionsMessages.SolutionsNotFoundMessage; return(result); } } catch (Exception exp) { result.Success = false; result.Message = exp.Message; return(result); } }