Esempio n. 1
0
        public virtual IActionResult ApiV1UsersGetAccountsByUserId(
            [FromRoute][Required] int?user_id
            )
        {
            if (!user_id.HasValue)
            {
                return(ApiResponseUtility.ApiError(
                           HttpStatusCode.BadRequest,
                           "user_id is required"
                           ));
            }

            var user = _userRepository.GetUserById(user_id.Value);

            if (user == null)
            {
                return(ApiResponseUtility.ApiError(
                           HttpStatusCode.NotFound,
                           $"User with id '{user_id}' does not exist"
                           ));
            }

            var accounts = _accountRepository.GetAllAccountsByUserId(user_id.Value).ToList();

            var models = accounts
                         .Select(ViewModelUtility.CreateAccountOverviewViewModel)
                         .ToList();

            return(Ok(models));
        }