public async Task <IActionResult> GetDesks(string userId)
        {
            if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                return(Unauthorized(new ResponseDm
                {
                    IsSuccess = false,
                    Message = "User not Authorized."
                }));
            }

            var roles = User.FindFirst(ClaimTypes.Role).Value.Split(",").ToList();

            var desks = await _profitLossService.GetDesksAsync(roles);

            return(Ok(desks));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetDailyPLTrades(string userId, string deskId, [FromQuery] DateTime businessDate)
        {
            if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                return(Unauthorized(new ResponseDm
                {
                    IsSuccess = false,
                    Errors = new List <string>
                    {
                        $"UserId - {userId}"
                    },
                    Message = $"Invalid UserId - {userId}"
                }));
            }

            var roles = User.FindFirst(ClaimTypes.Role).Value.Split(",").ToList();

            var accessDetails = await _profitLossService.GetDesksAsync(roles);

            if (!accessDetails.Any(x => x.DeskId == deskId))
            {
                return(Unauthorized(new ResponseDm
                {
                    IsSuccess = false,
                    Message = $"User Not Authorized access this Desk",
                    Errors = new List <string>
                    {
                        $"DeskId - {deskId}"
                    }
                }));
            }

            PLDeskDm dailyPlInfos = null;

            try
            {
                dailyPlInfos = await _profitLossService.GetDailyPLTradeAsync(deskId, businessDate);

                if (dailyPlInfos == null)
                {
                    return(NotFound(new ResponseDm
                    {
                        IsSuccess = false,
                        Message = "No Trades found."
                    }));
                }
            }
            catch (CustomDataException ex)
            {
                return(BadRequest(new ResponseDm
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
            catch (InvalidOperationException ex)
            {
                return(NotFound(new ResponseDm
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new ResponseDm
                {
                    IsSuccess = false,
                    Message = "Error occured. Please contact administrator."
                }));
            }
            return(Ok(dailyPlInfos));
        }