예제 #1
0
        public IActionResult GetInvestmentPrograms([FromHeader(Name = "Authorization")] string token, [FromBody] InvestmentProgramsFilter filter)
        {
            var data = trustManagementService.GetInvestmentPrograms(filter ?? new InvestmentProgramsFilter(), CurrentUser?.Id, CurrentUser?.Type);

            if (!data.IsSuccess)
            {
                return(BadRequest(ErrorResult.GetResult(data)));
            }

            return(Ok(new InvestmentProgramsViewModel
            {
                InvestmentPrograms = data.Data.Item1,
                Total = data.Data.Item2
            }));
        }
예제 #2
0
        public OperationResult <(List <InvestmentProgram>, int)> GetInvestmentPrograms(InvestmentProgramsFilter filter, Guid?userId, UserType?userType)
        {
            return(InvokeOperations.InvokeOperation(() =>
            {
                var query = context.InvestmentPrograms
                            .Include(x => x.ManagerAccount)
                            .ThenInclude(x => x.ManagersAccountsTrades)
                            .Include(x => x.ManagerAccount.ManagersAccountsStatistics)
                            .Include(x => x.Token)
                            .Include(x => x.InvestmentRequests)
                            .Include(x => x.Periods)
                            .AsQueryable();

                if (filter.ManagerId.HasValue)
                {
                    query = query.Where(x => x.ManagerAccountId == filter.ManagerId);
                }
                if (filter.BrokerId.HasValue)
                {
                    query = query.Where(x => x.ManagerAccount.BrokerTradeServer.BrokerId == filter.BrokerId);
                }
                if (filter.BrokerTradeServerId.HasValue)
                {
                    query = query.Where(x => x.ManagerAccount.BrokerTradeServerId == filter.BrokerTradeServerId);
                }
                if (filter.InvestMaxAmountFrom.HasValue)
                {
                    query = query.Where(x => x.InvestMinAmount >= filter.InvestMaxAmountFrom);
                }
                if (filter.InvestMaxAmountTo.HasValue)
                {
                    query = query.Where(x => x.InvestMaxAmount < filter.InvestMaxAmountTo);
                }

                if (filter.Sorting.HasValue)
                {
                    switch (filter.Sorting.Value)
                    {
                    case Sorting.ByRatingAsc:
                        query = query.OrderBy(x => x.Rating);
                        break;

                    case Sorting.ByRatingDesc:
                        query = query.OrderByDescending(x => x.Rating);
                        break;

                    case Sorting.ByOrdersAsc:
                        query = query.OrderBy(x => x.ManagerAccount.OrdersCount);
                        break;

                    case Sorting.ByOrdersDesc:
                        query = query.OrderByDescending(x => x.ManagerAccount.OrdersCount);
                        break;

                    case Sorting.ByProfitAsc:
                        query = query.OrderBy(x => x.ManagerAccount.ProfitTotal);
                        break;

                    case Sorting.ByProfitDesc:
                        query = query.OrderByDescending(x => x.ManagerAccount.ProfitTotal);
                        break;
                    }
                }
                else
                {
                    query = query.OrderByDescending(x => x.Rating);
                }

                var count = query.Count();

                if (filter.Skip.HasValue)
                {
                    query = query.Skip(filter.Skip.Value);
                }
                if (filter.Take.HasValue)
                {
                    query = query.Take(filter.Take.Value);
                }

                var programs = query.Select(x => x.ToInvestmentProgram(userId, userType)).ToList();

                return (programs, count);
            }));
        }