public async Task DonateNgoAsync(Guid ngoId, Guid userId, decimal value) { var ngoAndUser = await GetNgoAndUserAsync(ngoId, userId); var ngo = ngoAndUser.Item1; var user = ngoAndUser.Item2; var donation = user.DonateNgo(Guid.NewGuid(), ngo, value, "hash"); ngo.DonateChildren(donation); await _userRepository.UpdateAsync(user); await _ngoRepository.UpdateAsync(ngo); }
public async Task ApproveAsync(Guid id, string notes) { var ngo = await _ngoRepository.GetAsync(id); if (ngo == null) { throw new ServiceException("ngo_not_found", $"NGO with id: '{id}' was not found."); } ngo.Approve(notes); await _ngoRepository.UpdateAsync(ngo); }
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); }