Exemplo n.º 1
0
        private ApiResponse <int> Create(CreateTransactionViewModel model)
        {
            var apiResp = new ApiResponse <int>
            {
                Type = ResponseType.Fail
            };

            _transactionBusiness.OwnerId = GetUserId().Value;

            var now = DateTime.UtcNow;

            var transaction = new Dto.Transaction
            {
                CustomerId     = model.CustomerId.Value,
                TypeId         = model.TypeId.Value,
                Amount         = model.Amount.Value,
                Description    = model.Description,
                AttachmentName = model.AttachmentName,
                IsDebt         = _transactionBusiness.IsDebtTransaction(model.TypeId.Value),
                Date           = model.Date,
                ModifiedAt     = now,
                CreatedAt      = now
            };

            var resp = _transactionBusiness.Add(transaction);

            if (resp.Type != ResponseType.Success)
            {
                apiResp.ErrorCode = resp.ErrorCode;
                return(apiResp);
            }

            apiResp.Type = ResponseType.Success;
            apiResp.Data = transaction.Id;
            return(apiResp);
        }