public async Task <IActionResult> GetChanges([FromBody] GetChangesVm vm)
        {
            if (vm == null)
            {
                return(BadRequest());
            }

            int userId;

            try
            {
                userId = IdentityHelper.GetUserId(User);
            }
            catch (UnauthorizedAccessException)
            {
                return(Unauthorized());
            }

            await _upcomingExpenseService.DeleteOldAsync(userId);

            var getAll = new GetAll(userId, vm.LastSynced);

            IEnumerable <CategoryDto> categories = await _categoryService.GetAllAsync(getAll);

            IEnumerable <AccountDto> accounts = await _accountService.GetAllAsync(getAll);

            IEnumerable <TransactionDto> transactions = await _transactionService.GetAllAsync(getAll);

            IEnumerable <UpcomingExpenseDto> upcomingExpenses = await _upcomingExpenseService.GetAllAsync(getAll);

            IEnumerable <DebtDto> debts = await _debtService.GetAllAsync(getAll);

            var getDeletedIds = new GetDeletedIds(userId, vm.LastSynced);

            var changedVm = new ChangedVm
            {
                LastSynced                = DateTime.UtcNow,
                DeletedAccountIds         = await _accountService.GetDeletedIdsAsync(getDeletedIds),
                Accounts                  = accounts,
                DeletedCategoryIds        = await _categoryService.GetDeletedIdsAsync(getDeletedIds),
                Categories                = categories,
                DeletedTransactionIds     = await _transactionService.GetDeletedIdsAsync(getDeletedIds),
                Transactions              = transactions,
                DeletedUpcomingExpenseIds = await _upcomingExpenseService.GetDeletedIdsAsync(getDeletedIds),
                UpcomingExpenses          = upcomingExpenses,
                DeletedDebtIds            = await _debtService.GetDeletedIdsAsync(getDeletedIds),
                Debts = debts
            };

            return(Ok(changedVm));
        }
Example #2
0
 public Task <IEnumerable <int> > GetDeletedIdsAsync(GetDeletedIds model)
 {
     return(_accountsRepository.GetDeletedIdsAsync(model.UserId, model.FromDate));
 }
 public Task <IEnumerable <int> > GetDeletedIdsAsync(GetDeletedIds model)
 {
     return(_upcomingExpensesRepository.GetDeletedIdsAsync(model.UserId, model.FromDate));
 }