Ejemplo n.º 1
0
        public ActionResult GetWallet([FromBody] WalletBO wallet)
        {
            try
            {
                // GET SESSIONS
                SessionController sessionController = new SessionController();
                TblUserAuth       userAuth          = sessionController.GetSession(HttpContext.Session);

                UserAppService userAppService = new UserAppService();
                TblUserInfo    userInfo       = userAppService.Get(userAuth);

                List <WalletBO> walletBOs = new List <WalletBO>();
                WalletBO        walletBO  = new WalletBO();
                wallet.xPriv          = "Cardano private key";
                wallet.xPub           = "Cardano public key";
                wallet.Balance.Amount = 10m;

                walletBOs.Add(walletBO);

                return(Ok(walletBOs));
            }
            catch (Exception ex)
            {
                ApiResponseBO _apiResponse = new ApiResponseBO();
                _apiResponse.HttpStatusCode = "400";
                _apiResponse.Message        = ex.Message;
                _apiResponse.Status         = "Error";

                return(BadRequest(_apiResponse));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Create()
        {
            try
            {
                // GET SESSIONS
                SessionController sessionController = new SessionController();
                TblUserAuth       userAuth          = sessionController.GetSession(HttpContext.Session);

                UserAppService userAppService = new UserAppService();
                TblUserInfo    userInfo       = userAppService.Get(userAuth);

                WalletBO wallet = new WalletBO();
                wallet.xPriv = "Cardano private key";
                wallet.xPub  = "Cardano public key";

                return(Ok(wallet));
            }
            catch (Exception ex)
            {
                ApiResponseBO _apiResponse = new ApiResponseBO();
                _apiResponse.HttpStatusCode = "400";
                _apiResponse.Message        = ex.Message;
                _apiResponse.Status         = "Error";

                return(BadRequest(_apiResponse));
            }
        }
Ejemplo n.º 3
0
        public decimal GetAuthorAmount(Guid authorId)
        {
            var input  = new WalletBO().Sum(ConnectionHandler, x => x.Input, x => x.AuthorId == authorId);
            var output = new WalletBO().Sum(ConnectionHandler, x => x.Output, x => x.AuthorId == authorId);
            var dif    = input - output;

            return(dif.HasValue ? dif.Value : 0);
        }
Ejemplo n.º 4
0
        public ActionResult History([FromBody] WalletBO wallet)
        {
            try
            {
                // GET SESSIONS
                SessionController sessionController = new SessionController();
                TblUserAuth       userAuth          = sessionController.GetSession(HttpContext.Session);

                UserAppService userAppService = new UserAppService();
                TblUserInfo    userInfo       = userAppService.Get(userAuth);

                List <WalletTransactionBO> walletTransactions = new List <WalletTransactionBO>();

                WalletTransactionBO walletTransaction = new WalletTransactionBO();
                walletTransaction.From   = "from wallet address..";
                walletTransaction.To     = "to wallet address..";
                walletTransaction.Amount = 100f;

                walletTransactions.Add(walletTransaction);

                walletTransaction.From   = "from wallet address..";
                walletTransaction.To     = "to wallet address..";
                walletTransaction.Amount = 100f;

                walletTransactions.Add(walletTransaction);

                return(Ok(walletTransactions));
            }
            catch (Exception ex)
            {
                ApiResponseBO _apiResponse = new ApiResponseBO();
                _apiResponse.HttpStatusCode = "400";
                _apiResponse.Message        = ex.Message;
                _apiResponse.Status         = "Error";

                return(BadRequest(_apiResponse));
            }
        }
Ejemplo n.º 5
0
        public bool InsertPayment(Guid bookId, Guid customerId, long number)
        {
            base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
            var book = new BookBO().Get(base.ConnectionHandler, bookId);
            var sum  = book.Discount > 0 ? book.Price.Value - (book.Price.Value * book.Discount / 100) : book.Price.Value;

            try
            {
                var customerBook = new CustomerBook()
                {
                    BookId     = bookId,
                    CustomerId = customerId,
                    VIP        = true
                };
                if (!new CustomerBookBO().Insert(base.ConnectionHandler, customerBook))
                {
                    throw new KnownException("خطا در ذخیره اطلاعات");
                }
                var order = new Order()
                {
                    Number      = number,
                    OrderDate   = DateTime.Now.ShamsiDate(),
                    TotalAmount = book.Price.Value,
                    Discount    = book.Discount,
                    Amount      = sum,
                    Status      = PaymentStatus.Success,
                    CustomerId  = customerId,
                    BookId      = bookId
                };
                if (!new OrderBO().Insert(base.ConnectionHandler, order))
                {
                    throw new KnownException("خطا در ذخیره اطلاعات");
                }
                var peyment = new Payment()
                {
                    Number        = number,
                    OrderId       = order.Id,
                    Amount        = sum,
                    PaymentDate   = DateTime.Now.ShamsiDate(),
                    PaymentStatus = PaymentStatus.Success,
                    PaymentType   = PaymentType.Online,
                    PaymentRole   = PaymentRole.Success,
                    AuthorId      = book.AuthorId,
                    CustomerId    = customerId
                };
                if (!new PaymentBO().Insert(base.ConnectionHandler, peyment))
                {
                    throw new KnownException("خطا در ذخیره اطلاعات");
                }
                var walletBo = new WalletBO();
                var amount   = sum * book.Percent / 100;
                var wa       = new Wallet()
                {
                    AuthorId = book.AuthorId,
                    Amount   = amount,
                    Input    = amount,
                    Number   = number,
                    BookId   = bookId
                };
                if (!walletBo.Insert(base.ConnectionHandler, wa))
                {
                    throw new KnownException("خطا در ذخیره اطلاعات");
                }

                base.ConnectionHandler.CommitTransaction();
                return(true);
            }
            catch (Exception ex)
            {
                base.ConnectionHandler.RollBack();
                throw new KnownException(ex.Message);
            }
        }