Ejemplo n.º 1
0
        public async Task <IActionResult> GetCredits()
        {
            var userId = User.Claims.FirstOrDefault(c => c.Type == "id").Value;

            // check if user exists
            var userExists = await _identityService.CheckIfUserExists(userId);

            if (!userExists)
            {
                return(NotFound(new ErrorResponse(new ErrorModel {
                    Message = $"There is no user with id: {userId}"
                })));
            }

            var credits = await _creditService.GetUserCreditsASync(userId);

            if (credits == null)
            {
                return(NotFound(new ErrorResponse(new ErrorModel {
                    Message = $"There is no credit"
                })));
            }

            return(Ok(new Response <IList <CreditResponse> >(_mapper.Map <IList <CreditResponse> >(credits))));
        }