Exemplo n.º 1
0
        private async Task SendTransactionCommentPushNotificationAsync(TransactionCommentEditDto input)
        {
            var currentUser = await _sessionAppService.GetCurrentLoginInformations();

            var transaction = await _transactionRepository.GetAll()
                              .Include(t => t.Account)
                              .ThenInclude(account => account.Currency)
                              .Include(t => t.Category)
                              .Include(t => t.CreatorUser)
                              .Where(t => t.Id == input.TransactionId)
                              .FirstOrDefaultAsync();

            var transactionPreviewDto = ObjectMapper.Map <TransactionPreviewDto>(transaction);

            await _backgroundJobManager.EnqueueAsync <SendPushNotificationJob, SendPushNotificationJobArgs>(
                new SendPushNotificationJobArgs
            {
                Contents = input.Content,
                Headings = input.Id.HasValue
                        ? $"{currentUser.User.UserName.ToPascalCase()} updated a comment on a transaction done by {transactionPreviewDto.CreatorUserName}"
                        : $"New comment added by {currentUser.User.UserName.ToPascalCase()} on a transaction done by {transactionPreviewDto.CreatorUserName}.",
                Data        = GetTransactionDataInDictionary(transactionPreviewDto),
                TenancyName = currentUser.Tenant.TenancyName.Trim().ToLowerInvariant()
            });
        }
Exemplo n.º 2
0
        private async Task CreateTransactionCommentAsync(TransactionCommentEditDto input)
        {
            var transactionComment = ObjectMapper.Map <TransactionComment>(input);
            await _transactionCommentRepository.InsertAndGetIdAsync(transactionComment);

            await SendTransactionCommentPushNotificationAsync(input);
        }
Exemplo n.º 3
0
        private async Task <Result> SendTransactionCommentPushNotificationAsync(TransactionCommentEditDto input)
        {
            try
            {
                var currentUser = await _sessionAppService.GetCurrentLoginInformations();

                var transaction = await _transactionRepository.GetAll()
                                  .Include(t => t.Account)
                                  .ThenInclude(account => account.Currency)
                                  .Include(t => t.Category)
                                  .Include(t => t.CreatorUser)
                                  .Where(t => t.Id == input.TransactionId)
                                  .FirstOrDefaultAsync();

                var transactionPreviewDto = transaction.MapTo <TransactionPreviewDto>();

                return(await _notificationService.SendPushNotificationAsync(new PushNotificationInput()
                {
                    Contents = input.Content,
                    Headings = input.Id.HasValue
                         ? $"{currentUser.User.UserName.ToPascalCase()} updated a comment on a transaction done by {transactionPreviewDto.CreatorUserName}"
                         : $"New comment added by {currentUser.User.UserName.ToPascalCase()} on a transaction done by {transactionPreviewDto.CreatorUserName}.",
                    Data = GetTransactionDataInDictionary(transactionPreviewDto)
                }));
            }
            catch (Exception exception)
            {
                return(Result.Fail(exception.Message));
            }
        }
Exemplo n.º 4
0
        private async Task UpdateTransactionCommentAsync(TransactionCommentEditDto input)
        {
            var transactionComment = await _transactionCommentRepository.FirstOrDefaultAsync(c => c.Id == input.Id.Value);

            input.MapTo(transactionComment);

            await SendTransactionCommentPushNotificationAsync(input);
        }
Exemplo n.º 5
0
 public async Task CreateOrUpdateTransactionCommentAsync(TransactionCommentEditDto input)
 {
     if (input.Id.HasValue)
     {
         await UpdateTransactionCommentAsync(input);
     }
     else
     {
         await CreateTransactionCommentAsync(input);
     }
 }
Exemplo n.º 6
0
        private async Task <Result> CreateTransactionCommentAsync(TransactionCommentEditDto input)
        {
            try
            {
                var transactionComment = input.MapTo <TransactionComment>();
                await _transactionCommentRepository.InsertAndGetIdAsync(transactionComment);

                return(await SendTransactionCommentPushNotificationAsync(input));
            }
            catch (Exception exception)
            {
                return(Result.Fail(exception.Message));
            }
        }