public async Task <SettlementDetailsDto> GetAsync(Guid settlementId, Guid currentUserId) { var user = await _userRepository.HasAccessToSettlement(currentUserId, settlementId); var settlement = await _settlementRepository.GetAsync(settlementId); return(_mapper.Map <SettlementDetailsDto>(settlement)); }
public static async Task <Settlement> GetSettlementOrFailAsync(this ISettlementRepository repository, Guid id) { var settlement = await repository.GetAsync(id); if (settlement == null) { throw new Exception($"Settlement with id: '{id}' does not exist."); } return(settlement); }
public async Task UpdateAsync(Guid settlementId, Guid userId, Guid expenseId, string name, decimal cost) { var userExpenses = await _settlementRepository.GetExpensesOrFailAsync(settlementId, userId); var expense = userExpenses.SingleOrDefault(x => x.Id == expenseId); if (userExpenses == null) { throw new Exception($"Expense with id: '{expenseId}' does not exist."); } expense.SetName(name); expense.SetCost(cost); manager.Settle(await _settlementRepository.GetAsync(settlementId)); await _settlementRepository.UpdateExpenseAsync(settlementId, expense); }