Ejemplo n.º 1
0
        public async Task UpdateTransactionAsync(string categoryName, string id, TransactionPut transaction)
        {
            var userId = GetUserId();

            ValidationHelper.ValidateCategoryName(categoryName);
            ValidationHelper.ValidateTransactionId(id);

            if (transaction == null)
            {
                throw new ValidationErrorException("Transaction must be specified.");
            }
            Validator.CheckIsValid(transaction);

            var utcNow = Time.UtcNow;

            using (var persistence = Container.Get <IPersistenceService>())
            {
                var dbCategory = await GetCategoryAsync(persistence, userId, categoryName);

                var dbTransaction = await GetTransactionAsync(persistence, id, dbCategory.CategoryId);

                dbTransaction.USD        = transaction.Usd;
                dbTransaction.Comment    = transaction.Comment;
                dbTransaction.Date       = transaction.Date.Date;
                dbTransaction.ChangeDate = utcNow;

                await persistence.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
        public async Task <HttpResponseMessage> UpdateTransactionAsync([FromUri] string category, [FromUri] string id, [FromBody] TransactionPut transaction)
        {
            return(await ExecuteAsync(async() =>
            {
                var transactionService = Container.Get <ITransactionService>();

                await transactionService.UpdateTransactionAsync(category, id, transaction);

                return new Information {
                    Message = "Transaction updated."
                };
            }));
        }