Esempio n. 1
0
        public IHttpActionResult GetTransactionLogs()
        {
            try
            {
                var trService = new TrasactionService(db, User.Identity.Name);

                var logsList = trService.GetTransactionLogList();

                return(Ok(JsonConvert.SerializeObject(logsList)));
            }
            catch (Exception)
            {
                return(BadRequest("Server Error. Contact your administrator."));
            }
        }
Esempio n. 2
0
        public IHttpActionResult PostTransactionLog(TransactionLog transactionLog)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var trService = new TrasactionService(db, User.Identity.Name);

                var checkedResult = trService.CheckParties(transactionLog.RecipientId);
                if (checkedResult != "Ok")
                {
                    return(BadRequest(checkedResult));
                }

                checkedResult = trService.CheckSolvency(transactionLog.Sum);
                if (checkedResult != "Ok")
                {
                    return(BadRequest(checkedResult));
                }

                trService.CreateTransactionLog(transactionLog, out var recipientName);

                var response = new TransactionResponse()
                {
                    Total         = transactionLog.TotalSender,
                    Sum           = transactionLog.Sum * (-1),
                    TransferType  = TransferType.Credit.ToString(),
                    OperationDate = transactionLog.CreateDateTime.ToString("G"),
                    UserName      = recipientName
                };

                return(Ok(JsonConvert.SerializeObject(response)));
            }
            catch (Exception e)
            {
                return(BadRequest("Server Error. Contact your administrator."));
            }
        }