Esempio n. 1
0
        public TransactionDTO Post([FromBody] TransactionDTO transactionDTO)
        {
            Transaction trans = new Transaction();

            if (ModelState.IsValid)
            {
                if (transactionDTO.CardId is null)
                {
                    trans = new Transaction()
                    {
                        Number = transactionDTO.Number,
                        Amount = transactionDTO.Amount,
                        Card   = new Card()
                        {
                            Number         = transactionDTO.CardNumber.ToString(),
                            CardBrand      = transactionDTO.CardBrand,
                            CardholderName = transactionDTO.CardholderName,
                            CVS            = transactionDTO.CVS,
                            CardType       = transactionDTO.CardType,
                            ExpirationDate = transactionDTO.ExpirationDate
                        }
                    };
                }
            }
            else if (transactionDTO.CardId != null)
            {
                trans = new Transaction()
                {
                    Number = transactionDTO.Number,
                    Amount = transactionDTO.Amount,
                    Card   = new Card()
                    {
                        Id = Guid.Parse(transactionDTO.CardId)
                    }
                };
            }

            try
            {
                _TransactionBusiness.SaveAndUpdate(trans);

                _TransactionBusiness.Save();

                transactionDTO.TransactionId = trans.Id;

                transactionDTO.TypeTransaction = trans.TypeTransaction;

                TelemetryService.TraceTransactionSave(JsonConvert.SerializeObject(transactionDTO));
            }
            catch (Exception ex)
            {
                TelemetryService.TraceException(ex, JsonConvert.SerializeObject(transactionDTO));

                throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
            }



            return(transactionDTO);
        }