示例#1
0
        private async Task <(Ngo, User)> GetNgoAndUserAsync(Guid ngoId, Guid userId)
        {
            var ngo = await _ngoRepository.GetAsync(ngoId);

            if (ngo == null)
            {
                throw new ServiceException("ngo_not_found", $"NGO with id: '{ngoId}' was not found.");
            }
            var user = await _userRepository.GetAsync(userId);

            if (user == null)
            {
                throw new ServiceException("user_not_found", $"User with id: '{userId}'  was not found.");
            }

            return(ngo, user);
        }
示例#2
0
        private async Task ExecuteAsync(Guid ngoId, IList <ChildInfoDto> children,
                                        Action <Ngo, IEnumerable <Child> > action)
        {
            if (children == null || !children.Any())
            {
                throw new ServiceException("children_not_provided",
                                           $"Children were not provided for NGO with id: '{ngoId}'.");
            }
            var ngo = await _ngoRepository.GetAsync(ngoId);

            if (ngo == null)
            {
                throw new ServiceException("ngo_not_found",
                                           $"NGO with id: '{ngoId}' was not found.");
            }
            var ngoChildren = children.Select(x => new Child(x.Id, x.FullName, x.Gender,
                                                             x.Birthdate, x.Notes, x.NeededFunds > 0 ? x.NeededFunds : ngo.FundsPerChild));

            action(ngo, ngoChildren);
            await _ngoRepository.UpdateAsync(ngo);
        }
示例#3
0
 public async Task <NgoDto> GetAsync(Guid id)
 => _mapper.Map <NgoDto>(await _ngoRepository.GetAsync(id));