Ejemplo n.º 1
0
        public async Task <ServiceResult <int> > GetList(ClaimsPrincipal user, int groupId)
        {
            var group = groupsRepository.Get(groupId);

            if (group is null)
            {
                return(ServiceResult <int> .Error(404, "Group was not found"));
            }

            var authorizationResult = await authorizationService.AuthorizeAsync(user, group, GroupOperations.Read);

            if (!authorizationResult.Succeeded)
            {
                return(ServiceResult <int> .Error(401, "Unauthorized"));
            }

            var result = await transactionsRepository.GetList(groupId);

            if (result is null)
            {
                return(ServiceResult <int> .Error(404, "No transactions were found"));
            }
            return(ServiceResult <int> .Success(result.Select(TransactionViewModel.FromModel)));
        }