コード例 #1
0
        public IActionResult GetUserInfo(string loginName)
        {
            try
            {
                _log.Info($"GetUserInfo Callling: {loginName}");

                var obj = _userViewRepository.GetUserById(loginName);
                if (obj == null)
                {
                    return(StatusCode(401, new ErrorModel {
                        HttpStatusCode = 401, Message = "User Not Found"
                    }));
                }
                var userDto = _mapper.Map <UserDto>(obj);

                if (!string.IsNullOrWhiteSpace(userDto.GroupName))
                {
                    userDto.RoleCode = userDto.GroupName;
                }
                else if (!string.IsNullOrWhiteSpace(userDto.DealerCode))
                {
                    userDto.RoleCode = userDto.DealerCode;
                }
                else if (!string.IsNullOrWhiteSpace(userDto.ClientCode))
                {
                    userDto.RoleCode = userDto.ClientCode;
                }

                userDto.RoleName = _roleViewRepository.GetRoleById(userDto.RoleId)?.RoleName;

                return(Ok(userDto));
            }
            catch (Exception ex)
            {
                _log.Error($"Error in GetUserInfo - ", ex);
                return(StatusCode(500, new ErrorModel {
                    HttpStatusCode = 500, Message = "Internal Server Error"
                }));
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetNetPositionViewDetails(string userName)
        {
            try
            {
                var userDetails = _userViewRepository.GetUserById(userName);
                var role        = _roleRepository.GetRoles().Where(i => i.RoleId == userDetails.RoleId).FirstOrDefault().RoleName;
                _log.Info($"NetPositionController: GetNetPositionViewDetails Starting.. User: {userName} Role: {role}");

                var res = new List <NetPositionView>();

                if (role == Roles.SuperAdmin.ToString())
                {
                    res = (await _tradeViewGenericRepo.GetNetPositionView())?.ToList();
                }
                else if (role == Roles.Dealer.ToString())
                {
                    #region comment
                    //var clientCodes = await _tradeViewGenericRepo.GetClientCodesByDealerCode(userDetails.DealerCode);
                    //if(clientCodes?.Count > 0)
                    //{
                    //    res = (await _tradeViewGenericRepo.GetNetPositionViewByDealerClients(new List<string> { userDetails.DealerCode }, clientCodes)).ToList();
                    //}
                    #endregion

                    var dealerCodes = new List <string> {
                        userDetails.DealerCode
                    };
                    if (dealerCodes?.Count > 0)
                    {
                        res = (await _tradeViewGenericRepo.GetNetPoistionViewByDealerCodes(dealerCodes)).ToList();
                    }
                }
                else if (role == Roles.GroupUser.ToString())
                {
                    #region comment
                    //var clientCodes = await _tradeViewGenericRepo.GetClientCodesByGroupName(userDetails.GroupName);
                    //if (clientCodes?.Count > 0)
                    //{
                    //    res = (await _tradeViewGenericRepo.GetNetPositionViewByClients(clientCodes)).ToList();
                    //}
                    #endregion

                    var dealerCodes = _groupDealerMappingRepository.GetDealerByGroupName(userDetails.GroupName).ToList();
                    if (dealerCodes?.Count > 0)
                    {
                        res = (await _tradeViewGenericRepo.GetNetPoistionViewByDealerCodes(dealerCodes)).ToList();
                    }
                }
                else if (role == Roles.Client.ToString())
                {
                    res = (await _tradeViewGenericRepo.GetNetPositionViewByClients(new List <string> {
                        userDetails.ClientCode
                    })).ToList();
                }

                _log.Info($"NetPositionController: GetNetPositionViewDetails Finished.. Count:{res?.ToList().Count}");
                return(Ok(res));
            }
            catch (Exception ex)
            {
                _log.Error("Error in GetNetPositionViewDetails ", ex);
                return(StatusCode(500));
            }
        }
コード例 #3
0
        public async Task <IActionResult> GetAllTrades(string userName)
        {
            try
            {
                _log.Info($"TradeViewController - In GetAllTrades userName-{userName}");

                var resultSet = new List <TradeViewDto>();

                //var tradeDetails = _tradeViewRepository.GetTradeViews();
                //if (tradeDetails == null)
                //    return NotFound();

                //foreach (var item in tradeDetails)
                //{
                //    resultSet.Add(_mapper.Map<TradeViewDto>(item));
                //}

                _log.Info($"In GetAllTrades Started");
                ConcurrentBag <TradeView> tradeDetails = new ConcurrentBag <TradeView>();
                var userDetails = _userViewRepository.GetUserById(userName);
                var role        = _roleViewRepository.GetRoles().Where(i => i.RoleId == userDetails.RoleId).FirstOrDefault().RoleName;

                if (role == Roles.SuperAdmin.ToString())
                {
                    var tradeCount = await _tradeViewGenericRepository.GetAllTradesCount();

                    var iteration = Math.Ceiling(Convert.ToDecimal(tradeCount) / DataAccess.Repository.Constants.ChunkCount);
                    int offset    = 0;
                    //for (int i = 0; i < iteration; i++)
                    //{
                    //    _log.Info($"TradeViewController - GetAllTrades userName-{userName} ChunkIndex-[{i}]");
                    //    var trades = await _tradeViewGenericRepository.GetAllTradeViewsByPageIndex(offset);
                    //    tradeDetails.AddRange(trades);
                    //    offset += DataAccess.Repository.Constants.ChunkCount;
                    //}
                    //tradeDetails = trades.ToList();

                    var lstOffset = new List <int> {
                        offset
                    };
                    for (int i = 0; i < iteration - 1; i++)
                    {
                        offset += DataAccess.Repository.Constants.ChunkCount;
                        lstOffset.Add(offset);
                    }

                    Parallel.ForEach(lstOffset, offset =>
                    {
                        _log.Info($"TradeViewController - GetAllTrades userName-{userName} ChunkIndex-[{offset}]");
                        var trades = _tradeViewGenericRepository.GetAllTradeViewsByPageIndex(offset);
                        tradeDetails.AddRange <TradeView>(trades.Result);
                    });
                }
                else if (role == Roles.GroupUser.ToString())
                {
                    #region Comment
                    //var clientCodes = await _tradeViewGenericRepository.GetClientCodesByGroupName(userDetails.GroupName);
                    //if (clientCodes?.Count > 0)
                    //{
                    //    var tardecount = await _tradeViewGenericRepository.GetAllTradesCountByDealersAndClientCodes(clientCodes, new List<string> { userDetails.DealerCode });
                    //    var iteration = Math.Ceiling(Convert.ToDecimal(tardecount) / DataAccess.Repository.Constants.ChunkCount);
                    //    int offset = 0;
                    //    var lstOffset = new List<int> { offset };
                    //    for (int i = 0; i < iteration - 1; i++)
                    //    {
                    //        offset += DataAccess.Repository.Constants.ChunkCount;
                    //        lstOffset.Add(offset);
                    //    }

                    //    Parallel.ForEach(lstOffset, offset =>
                    //    {
                    //        _log.Info($"TradeViewController - GetAllTrades userName-{userName} ChunkIndex-[{offset}]");
                    //        var trades = _tradeViewGenericRepository.GetAllTradeViewsByDealerCodesClientCodes(clientCodes,new List<string> { userDetails.DealerCode }, offset);
                    //        tradeDetails.AddRange<TradeView>(trades.Result);
                    //    });
                    //}
                    #endregion

                    var dealerCodes = _groupDealerMappingRepository.GetDealerByGroupName(userDetails.GroupName);
                    if (dealerCodes.Count > 0)
                    {
                        _log.Info($"TradeViewController: DealerCodes-{JsonSerializer.Serialize(dealerCodes)}");
                        var tardecount = await _tradeViewGenericRepository.GetTadesCountByDealerCode(dealerCodes.ToList());

                        var iteration = Math.Ceiling(Convert.ToDecimal(tardecount) / DataAccess.Repository.Constants.ChunkCount);
                        int offset    = 0;
                        var lstOffset = new List <int> {
                            offset
                        };
                        for (int i = 0; i < iteration - 1; i++)
                        {
                            offset += DataAccess.Repository.Constants.ChunkCount;
                            lstOffset.Add(offset);
                        }
                        Parallel.ForEach(lstOffset, offset =>
                        {
                            _log.Info($"TradeViewController - GetAllTrades userName-{userName} | DealerCode-{dealerCodes.ToArray()} | ChunkIndex-[{offset}]");
                            var trades = _tradeViewGenericRepository.GetTradesByDealerCode(dealerCodes.ToList(), offset);
                            tradeDetails.AddRange <TradeView>(trades.Result);
                        });
                    }
                }
                else if (role == Roles.Dealer.ToString())
                {
                    #region Comment
                    //var clientCodes = await _tradeViewGenericRepository.GetClientCodesByDealerCode(userDetails.DealerCode);
                    //if (clientCodes?.Count > 0)
                    //{
                    //    var tardecount = await _tradeViewGenericRepository.GetAllTradesCountByDealerClientCode(clientCodes, userDetails.DealerCode);
                    //    var iteration = Math.Ceiling(Convert.ToDecimal(tardecount) / DataAccess.Repository.Constants.ChunkCount);
                    //    int offset = 0;
                    //    var lstOffset = new List<int> { offset };
                    //    for (int i = 0; i < iteration - 1; i++)
                    //    {
                    //        offset += DataAccess.Repository.Constants.ChunkCount;
                    //        lstOffset.Add(offset);
                    //    }

                    //    Parallel.ForEach(lstOffset, offset =>
                    //    {
                    //        _log.Info($"TradeViewController - GetAllTrades userName-{userName} ChunkIndex-[{offset}]");
                    //        var trades = _tradeViewGenericRepository.GetAllTradeViewsByDealerCodeClientCodes(clientCodes, userDetails.DealerCode, offset);
                    //        tradeDetails.AddRange<TradeView>(trades.Result);
                    //    });
                    //}
                    #endregion

                    if (!string.IsNullOrWhiteSpace(userDetails.DealerCode))
                    {
                        var tardecount = await _tradeViewGenericRepository.GetTadesCountByDealerCode(new List <string> {
                            userDetails.DealerCode
                        });

                        var iteration = Math.Ceiling(Convert.ToDecimal(tardecount) / DataAccess.Repository.Constants.ChunkCount);
                        int offset    = 0;
                        var lstOffset = new List <int> {
                            offset
                        };
                        for (int i = 0; i < iteration - 1; i++)
                        {
                            offset += DataAccess.Repository.Constants.ChunkCount;
                            lstOffset.Add(offset);
                        }
                        Parallel.ForEach(lstOffset, offset =>
                        {
                            _log.Info($"TradeViewController - GetAllTrades userName-{userName} | DealerCode-{userDetails.DealerCode} | ChunkIndex-[{offset}]");
                            var trades = _tradeViewGenericRepository.GetTradesByDealerCode(new List <string> {
                                userDetails.DealerCode
                            }, offset);
                            tradeDetails.AddRange <TradeView>(trades.Result);
                        });
                    }
                }
                else if (role == Roles.Client.ToString() && !string.IsNullOrWhiteSpace(userDetails.ClientCode))
                {
                    var clientCodes = new List <string> {
                        userDetails.ClientCode
                    };
                    if (clientCodes?.Count > 0)
                    {
                        var tardecount = await _tradeViewGenericRepository.GetAllTradesCountByClientCode(clientCodes);

                        var iteration = Math.Ceiling(Convert.ToDecimal(tardecount) / DataAccess.Repository.Constants.ChunkCount);
                        int offset    = 0;
                        var lstOffset = new List <int> {
                            offset
                        };
                        for (int i = 0; i < iteration - 1; i++)
                        {
                            offset += DataAccess.Repository.Constants.ChunkCount;
                            lstOffset.Add(offset);
                        }

                        Parallel.ForEach(lstOffset, offset =>
                        {
                            _log.Info($"TradeViewController - GetAllTrades userName-{userName} ChunkIndex-[{offset}]");
                            var trades = _tradeViewGenericRepository.GetAllTradeViewsByClientCodes(clientCodes, offset);
                            tradeDetails.AddRange <TradeView>(trades.Result);
                        });

                        //var trades = await _tradeViewGenericRepository.GetAllTradeViewsByClientCodes(clientCodes);
                        //tradeDetails.AddRange<TradeView>(trades.ToList());
                    }
                }
                else
                {
                    return(StatusCode(204, ModelState));
                }

                //if (tradeDetails == null || tradeDetails.Count == 0)
                //    return NotFound();
                foreach (var item in tradeDetails.OrderByDescending(i => i.TradeViewId))
                {
                    if (item.StrikePrice == string.Empty)
                    {
                        item.StrikePrice = null;
                    }
                    if (item.TradePrice == string.Empty)
                    {
                        item.TradePrice = null;
                    }
                    resultSet.Add(_mapper.Map <TradeViewDto>(item));
                }

                _log.Info($"TradeViewController - In GetAllTrades Finished Count-{resultSet.Count}");

                return(Ok(resultSet));
            }
            catch (Exception ex)
            {
                _log.Error("Error in GetAllTrades ", ex);
                return(StatusCode(500, ModelState));
            }
        }