Beispiel #1
0
        public IActionResult Get([FromBody] ScoreCredentials oldScore)
        {
            var idClaim = User.Claims.FirstOrDefault(x => x.Type.Equals(JwtRegisteredClaimNames.Jti, StringComparison.InvariantCultureIgnoreCase));

            if (idClaim != null)
            {
                Guid tokenGuid = Guid.Parse(idClaim.ToString().Remove(0, 5));

                var scService = new ScoreService();
                scService.WorkScore(new ScoreModel {
                    ClientId = tokenGuid, NumScore = oldScore.ScoreFrom
                }, "UPDATE scores SET exist = false WHERE clientid = @clientid AND numscore = @numscore;");
                return(Ok("Score closed"));
            }
            return(BadRequest("Try to enter one more time"));
        }
Beispiel #2
0
        public IActionResult Get([FromBody] ScoreCredentials extractor)
        {
            var idClaim = User.Claims.FirstOrDefault(x =>
                                                     x.Type.Equals(JwtRegisteredClaimNames.Jti, StringComparison.InvariantCultureIgnoreCase));

            if (idClaim != null)
            {
                Guid   tokenGuid       = Guid.Parse(idClaim.ToString().Remove(0, 5));
                var    histService     = new HistoryService();
                var    scService       = new ScoreService();
                var    clService       = new ClientService();
                var    workerCount     = 0;
                var    oldCount        = 1;
                string clientHistories = "Client: " + clService.ReturnClient(new ClientModel {
                    UserGuid = tokenGuid
                }, "SELECT * FROM clients WHERE userguid = @userguid;").RealName + "\r\n";
                clientHistories = clientHistories + clService.ReturnClient(new ClientModel {
                    UserGuid = tokenGuid
                }, "SELECT * FROM clients WHERE userguid = @userguid;").ClientName + "\r\n";
                clientHistories = clientHistories + "Detalization of: #" + extractor.ScoreFrom + "\r\n\r\n";
                while (workerCount != oldCount)
                {
                    try
                    {
                        var showHistory = histService.ReturnHistory(new HistoryModel {
                            ScoreFrom = extractor.ScoreFrom, Id = workerCount, ClientId = tokenGuid
                        },
                                                                    "SELECT * FROM viewhistories WHERE (scorefrom = @scorefrom AND clientid = @clientid AND id >= @id) OR (scoreto = @scorefrom AND takerid = @clientid AND id >= @id);");
                        oldCount    = workerCount;
                        workerCount = showHistory.Id + 1;
                        if (showHistory.ScoreFrom.Equals("4000000000"))
                        {
                            clientHistories       = clientHistories + "Refill ";
                            showHistory.ScoreFrom = "Deposit";
                        }
                        else if (scService.ReturnScore(
                                     new ScoreModel {
                            ClientId = tokenGuid, NumScore = showHistory.ScoreTo
                        },
                                     "SELECT * FROM scores WHERE numscore=@numscore AND clientid=@clientid") != null && scService.ReturnScore(
                                     new ScoreModel {
                            ClientId = tokenGuid, NumScore = showHistory.ScoreFrom
                        },
                                     "SELECT * FROM scores WHERE numscore=@numscore AND clientid=@clientid") != null)
                        {
                            clientHistories = clientHistories + "Transfer ";
                        }
                        else
                        {
                            clientHistories = clientHistories + "Payment ";
                        }
                        if (showHistory.Template)
                        {
                            clientHistories = clientHistories + "by template ";
                        }
                        clientHistories = clientHistories + showHistory.SentTime + "\r\nFrom: " + showHistory.ScoreFrom;
                        clientHistories = clientHistories + "   To:" + showHistory.ScoreTo + "\r\n";
                        clientHistories = clientHistories + "   " + showHistory.HowMuch + " rub" + "\r\n\r\n";
                    }
                    catch
                    {
                        workerCount = oldCount;
                        if (clientHistories.Length > 4)
                        {
                            clientHistories = clientHistories.Substring(0, clientHistories.Length - 4);
                        }
                    }
                }
                return(Ok(clientHistories));
            }
            return(BadRequest("No claim"));
        }
        public ActionResult Get([FromBody] ScoreCredentials score)
        {
            var idClaim = User.Claims.FirstOrDefault(x => x.Type.Equals(JwtRegisteredClaimNames.Jti, StringComparison.InvariantCultureIgnoreCase));

            if (idClaim != null)
            {
                Guid tokenGuid = Guid.Parse(idClaim.ToString().Remove(0, 5));

                if (score.ScoreFrom == "AddMoney") // Если вместо сходного счёта эта строка, то деньги добавляем из буферного счёта для сторонних поступлений
                {
                    tokenGuid       = new Guid("f414ec5a-a585-4368-beec-6b488cf76b51");
                    score.ScoreFrom = "4000000000";
                }
                var istemplate  = false;
                var scService   = new ScoreService();
                var clService   = new ClientService();
                var histService = new HistoryService();
                var takeScore   = scService.ReturnScore(new ScoreModel {
                    ClientId = tokenGuid, NumScore = score.ScoreFrom
                }, "SELECT * FROM scores WHERE clientid = @clientid AND numscore = @numscore AND exist = TRUE;");
                var   cashLess = takeScore.Cash;
                float cashMore;
                try
                {
                    var showScore = scService.ReturnScore(new ScoreModel {
                        NumScore = score.ScoreTo
                    }, "SELECT * FROM scores WHERE numscore = @numscore AND exist = TRUE;");
                    cashMore = showScore.Cash;
                }
                catch
                {
                    return(BadRequest("Check number"));
                }

                if (cashLess >= score.HowMuch) // проверить соответствие принимающей стороны
                {
                    var takerId = clService.ReturnClient(new ClientModel {
                        ClientName = score.TakerName
                    },
                                                         "SELECT * FROM clients WHERE clientname = @clientname");

                    if (scService.ReturnScore(new ScoreModel {
                        NumScore = score.ScoreTo, ClientId = takerId.UserGuid
                    }, "SELECT * FROM scores WHERE clientid = @clientid AND numscore = @numscore AND exist = TRUE;") != null)                                                                                             // проверить, принадлежит ли номер счёта принимателю
                    {
                        cashLess = cashLess - score.HowMuch;
                        cashMore = cashMore + score.HowMuch;
                        scService.WorkScore(new ScoreModel {
                            NumScore = score.ScoreFrom, Cash = cashLess, ClientId = tokenGuid
                        }, "UPDATE scores SET cash = @cash WHERE clientid = @clientid AND numscore = @numscore;");
                        scService.WorkScore(new ScoreModel {
                            NumScore = score.ScoreTo, Cash = cashMore, ClientId = takerId.UserGuid
                        }, "UPDATE scores SET cash = @cash WHERE clientid = @clientid AND numscore = @numscore AND exist = TRUE;");
                        if (score.IsTemplate == "true")
                        {
                            istemplate = true;
                        }

                        histService.WorkHistory(new HistoryModel {
                            ScoreFrom = score.ScoreFrom, ScoreTo = score.ScoreTo, HowMuch = score.HowMuch, ClientId = tokenGuid, TakerId = takerId.UserGuid, Template = istemplate
                        },
                                                "INSERT INTO histories(scorefrom, scoreto, howmuch, clientid, takerid, template) VALUES (@scorefrom, @scoreto, @howmuch, @clientid, @takerid, @template);");
                        return(Ok("Moneys has been sent"));
                    }
                    return(BadRequest("Check acceptor name!"));
                }
                return(BadRequest("No money"));
            }
            return(BadRequest("No claim"));
        }