public async Task <IActionResult> GetTransactions(TransactionsParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(await Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(await Error(HttpStatusCode.BadRequest, "page", "Invalid request parameters"));
            }

            var transactionDto = _transactionApiService.GetTransactions(
                parameters.Ids,
                parameters.Limit,
                parameters.Page,
                parameters.SinceId,
                parameters.CreatedAtMin,
                parameters.CreatedAtMax)
                                 .Select(trans => trans.ToDto()).ToList();

            var rootObject = new TransactionsRootObject {
                Transactions = transactionDto
            };

            var json = JsonFieldsSerializer.Serialize(rootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
        public async Task <IActionResult> CreateTransaction([ModelBinder(typeof(JsonModelBinder <TransactionDto>))] Delta <TransactionDto> transDelta)
        {
            if (!ModelState.IsValid)
            {
                return(await Error());
            }

            var newTransaction = new Transaction();

            transDelta.Merge(newTransaction);

            await _transactionRepository.InsertAsync(newTransaction);

            await UserActivityService.InsertActivityAsync("AddNewTransaction", $"Added a new transaction (ID = {newTransaction.Id})", newTransaction);

            var newTransactionDto = newTransaction.ToDto();

            var rootObject = new TransactionsRootObject();

            rootObject.Transactions.Add(newTransactionDto);

            var json = JsonFieldsSerializer.Serialize(rootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
        public async Task <IActionResult> UpdateTransaction([ModelBinder(typeof(JsonModelBinder <TransactionDto>))] Delta <TransactionDto> transDelta)
        {
            if (!ModelState.IsValid)
            {
                return(await Error());
            }

            var currentTransaction = _transactionApiService.GetTransactionById(transDelta.Dto.Id);

            if (currentTransaction == null)
            {
                return(await Error(HttpStatusCode.NotFound, "transaction", "not found"));
            }

            transDelta.Merge(currentTransaction);

            await _transactionRepository.UpdateAsync(currentTransaction);

            await UserActivityService.InsertActivityAsync("EditTransaction", $"Edited a transaction (ID = {currentTransaction.Id})", currentTransaction);

            var transactionDto = currentTransaction.ToDto();

            var rootObject = new TransactionsRootObject();

            rootObject.Transactions.Add(transactionDto);

            var json = JsonFieldsSerializer.Serialize(rootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
        protected async Task <IActionResult> RootObjectResult(IList <TransactionDto> entities, string fields)
        {
            var rootObj = new TransactionsRootObject {
                Transactions = entities
            };

            var json = JsonFieldsSerializer.Serialize(rootObj, fields);

            return(await Task.FromResult <IActionResult>(new RawJsonActionResult(json)));
        }
        public async Task <IActionResult> GetTransactionById(int id, string fields = "")
        {
            if (id <= 0)
            {
                return(await Error(HttpStatusCode.BadRequest, "id", "invalid id"));
            }

            var transaction = _transactionApiService.GetTransactionById(id);

            if (transaction == null)
            {
                return(await Error(HttpStatusCode.NotFound, "transaction", "not found"));
            }

            var rootObject = new TransactionsRootObject();

            rootObject.Transactions.Add(transaction.ToDto());

            var json = JsonFieldsSerializer.Serialize(rootObject, fields);

            return(new RawJsonActionResult(json));
        }