Exemplo n.º 1
0
        public async Task <JsonResult> ReceiveReceipt(Receipt1 receipts)
        {
            var bcg     = new BarCodeGenerator();
            var account = await BetDatabase.Accounts.SingleOrDefaultAsync(x => x.UserId == User.Identity.Name);

            var branchId = Convert.ToInt32(account.AdminE);
            var branch   = await BetDatabase.Branches.SingleOrDefaultAsync(x => x.BranchId == branchId);

            var receiptid = bcg.GenerateRandomString(16);
            var receipt   = new Receipt
            {
                UserId        = User.Identity.Name,
                BranchId      = Convert.ToInt16(account.AdminE),
                ReceiptStatus = 0,
                SetNo         = 2014927,
                // ReceiptId = Convert.ToInt32(receiptid)
            }; //Start New Reciept

            var    betStake = receipts.TotalStake.ToString(CultureInfo.InvariantCulture);
            string response;

            BetDatabase.Receipts.Add(receipt);
            await BetDatabase.SaveChangesAsync();

            var         ttodd        = receipts.TotalOdd;
            const float bettingLimit = 8000000;
            var         cost         = Convert.ToDouble(betStake);

            if ((cost >= 1000) && (cost <= bettingLimit))//betting limit
            {
                foreach (var betData in receipts.BetData)
                {
                    try
                    {
                        var      tempMatchId = Convert.ToInt32(betData.MatchId);
                        var      _matchid    = BetDatabase.ShortMatchCodes.Single(x => x.ShortCode == tempMatchId).MatchNo;
                        Match    _match      = BetDatabase.Matches.Single(h => h.MatchNo == _matchid);
                        DateTime _matchTime  = _match.StartTime;
                        DateTime timenow     = DateTime.Now;
                        if (_matchTime < timenow)
                        {
                            response = ("The Match " + tempMatchId + " Has Started");
                            return(new JsonResult {
                                Data = new { message = response }
                            });
                        }
                        var bm = new Bet
                        {
                            BetOptionId = Int32.Parse(betData.OptionId),
                            RecieptId   = receipt.ReceiptId,
                            MatchId     = BetDatabase.ShortMatchCodes.Single(x => x.ShortCode == tempMatchId).MatchNo,
                            BetOdd      = Convert.ToDecimal(betData.Odd),
                        };
                        BetDatabase.Bets.Add(bm);
                        BetDatabase.SaveChanges();
                    }
                    catch (Exception er)
                    {
                        response = (" An error  has occured:" + er.Message);
                        return(new JsonResult {
                            Data = new { message = response }
                        });

                        var msg = er.Message;
                    }
                }
                // Requires Quick Attention

                receipt.TotalOdds     = Convert.ToDouble(ttodd);
                receipt.ReceiptStatus = 1;
                receipt.SetSize       = receipts.ReceiptSize;
                receipt.Stake         = cost;
                receipt.WonSize       = 0;
                receipt.SubmitedSize  = 0;
                receipt.ReceiptDate   = DateTime.Now;
                receipt.Serial        = Int2Guid(receiptid);
                account.DateE         = DateTime.Now;
                // receipt.RecieptID = 34;
                BetDatabase.Entry(receipt).State = EntityState.Modified;
                var statement = new Statement
                {
                    Account        = receipt.UserId,
                    Amount         = receipt.Stake,
                    Controller     = receipt.UserId,
                    StatetmentDate = DateTime.Now,
                    BalBefore      = account.AmountE,
                    BalAfter       = account.AmountE + receipt.Stake,
                    Comment        = "Bet Transaction for Ticket No" + receiptid
                };
                account.AmountE       = account.AmountE + receipt.Stake;
                statement.Transcation = "Teller Bet";
                statement.Method      = "Online";
                statement.Serial      = receiptid;

                branch.Balance = branch.Balance + Convert.ToDecimal(receipt.Stake);
                BetDatabase.Entry(branch).State = EntityState.Modified;
                BetDatabase.Accounts.AddOrUpdate(account);
                BetDatabase.Statements.Add(statement);
                BetDatabase.SaveChanges();
                var barcodeImage = bcg.CreateBarCode(receiptid);
                var tempPath     = Server.MapPath("~/Content/BarCodes/" + receiptid.Trim() + ".png");
                try
                {
                    barcodeImage.Save(tempPath, ImageFormat.Png);
                }
                catch (Exception)
                {
                }
                response = ("Success");
            }
            else if (cost < 1000)
            {
                receipt.ReceiptId = 0;
                response          = ("Minimum betting stake is UGX 1000. Please enter amount more than UGX 1000.");
            }
            else
            {
                receipt.ReceiptId = 0;
                response          = ("Maximum stake is UGX " + bettingLimit + ". Please enter amount less than UGX " + bettingLimit + ".");
            }

            return(new JsonResult {
                Data = new { message = response, ReceiptNumber = receipt.ReceiptId, ReceiptTime = String.Format("{0:dd/MM/yyyy}", DateTime.Now) + " - " + toJavaScriptDate(DateTime.Now), TellerName = account.UserId, BranchName = branch.BranchName, Balance = account.AmountE, Serial = receiptid, FormatedSerial = GetSerialNumber(receiptid) }
            });
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> ReceiveReceipt([FromBody] Receipt1 receipts)
        {
            var bcg       = new BarCodeGenerator();
            var receiptid = bcg.GenerateRandomString(16);
            // IEnumerable<string> headerValues =RequestContext.Principal..PrincipalIdentityrequest.Headers.GetValues("MyCustomID");
            // var id = headerValues.FirstOrDefault();
            //var identity = (ClaimsIdentity)User.Identity;
            //Claim claims = identity.FindFirst("UserName");
            //var un = RequestContext.Principal.Identity.Name;
            // var userName = RequestContext.Principal.Identity.Name;//context.Request.User.Identity.Name;
            // ClaimsPrincipal principle = Request.GetRequestContext().Principal as ClaimsPrincipal;
            // var userName = principle.Claims.Where(c => c.Type == "sub").SingleOrDefault().Value;

            // var user = this.User.Identity;
            var userName = receipts.UserName;
            var account  = BetDatabase.Accounts.SingleOrDefault(x => x.UserId == userName);
            //if (account == null)
            //{
            //    account = new Account
            //    {
            //        DateE = DateTime.Now,
            //        UserId = userName,

            //    };
            //    BetDatabase.Accounts.Add(account);
            //    BetDatabase.SaveChanges();
            //}
            string response = "";

            if (account == null)
            {
                response = "Invalid user name or password please sign in or contact tour systems admin";
                return(Ok(new { message = response }));
            }
            var    branchId = /* 1;*/ Convert.ToInt32(account.AdminE);
            Branch branch   = await BetDatabase.Branches.SingleOrDefaultAsync(x => x.BranchId == branchId);

            var         betStake     = receipts.TotalStake.ToString(CultureInfo.InvariantCulture);
            var         ttodd        = receipts.TotalOdd;
            const float bettingLimit = 200000000;
            var         cost         = Convert.ToDouble(betStake);
            var         receipt      = new Receipt
            {
                UserId   = /*"TellerTest",*//*User.Identity.Name*/ userName,
                BranchId = /*= 1,*/ Convert.ToInt16(account.AdminE),
                // ReceiptStatus = 0,
                SetNo         = 2014927,
                TotalOdds     = Convert.ToDouble(ttodd),
                ReceiptStatus = 1,
                SetSize       = receipts.ReceiptSize,
                Stake         = cost,
                WonSize       = 0,
                SubmitedSize  = 0,
                ReceiptDate   = DateTime.Now,
                Serial        = Int2Guid(receiptid),
                // ReceiptId = Convert.ToInt32(receiptid)
            }; //Start New Reciept


            // string response;


            account.DateE = DateTime.Now;
            BetDatabase.Receipts.Add(receipt);
            await BetDatabase.SaveChangesAsync();

            //////var ttodd = receipts.TotalOdd;
            //////const float bettingLimit = 8000000;
            //////var cost = Convert.ToDouble(betStake);
            if ((cost >= 3000) && (cost <= bettingLimit))//betting limit
            {
                foreach (var betData in receipts.BetData)
                {
                    try
                    {
                        //var tempMatchId = Convert.ToInt32(betData.MatchId);
                        var matchid = 0;
                        //Check if the match is a live game
                        if (betData.LiveScores != null)
                        {
                            var tempMatchIdLive = betData.MatchId;
                            matchid = (int)BetDatabase.LiveMatches.Single(x => x.LiveMatchNo.Equals(tempMatchIdLive)).BetServiceMatchNo;
                        }
                        else
                        {
                            var tempMatchIdNormals = Convert.ToInt32(betData.MatchId);
                            matchid = BetDatabase.ShortMatchCodes.Single(x => x.ShortCode == tempMatchIdNormals).MatchNo;
                        }
                        Match    match      = BetDatabase.Matches.Single(h => h.BetServiceMatchNo == matchid);
                        DateTime _matchTime = match.StartTime;
                        DateTime timenow    = DateTime.Now;
                        //if (_matchTime < timenow)
                        //{
                        //    response = ("The Match " + tempMatchId + " Has Started");
                        //    var message = response;
                        //    return Ok(message);
                        //}
                        var bm = new Bet
                        {
                            BetOptionId = Int32.Parse(betData.OptionId),
                            RecieptId   = receipt.ReceiptId,
                            MatchId     = Convert.ToInt32(matchid),// MatchId = BetDatabase.ShortMatchCodes.Single(x => x.ShortCode == tempMatchId).MatchNo,
                            BetOdd      = Convert.ToDecimal(betData.Odd),
                            ExtraValue  = GetExtraValue(betData.ExtraValue),
                            BetMinute   = _timeFormmater.formatMinutes(betData.BetMinute)
                        };
                        BetDatabase.Bets.Add(bm);
                        BetDatabase.SaveChanges();
                    }
                    catch (Exception er)
                    {
                        var message = response = (" An error  has occured:" + er.Message);
                        return(Ok(message));

                        var msg = er.Message;
                    }
                }
                // Requires Quick Attention

                //////receipt.TotalOdds = Convert.ToDouble(ttodd);
                //////receipt.ReceiptStatus = 1;
                //////receipt.SetSize = receipts.ReceiptSize;
                //////receipt.Stake = cost;
                //////receipt.WonSize = 0;
                //////receipt.SubmitedSize = 0;
                //////receipt.ReceiptDate = DateTime.Now;
                //////receipt.Serial = Int2Guid(receiptid);
                //////account.DateE = DateTime.Now;
                // receipt.RecieptID = 34;
                BetDatabase.Entry(receipt).State = EntityState.Modified;
                var statement = new Statement
                {
                    Account        = receipt.UserId,
                    Amount         = receipt.Stake,
                    Controller     = receipt.UserId,
                    StatetmentDate = DateTime.Now,
                    BalBefore      = account.AmountE,
                    BalAfter       = account.AmountE + receipt.Stake,
                    Comment        = "Bet Transaction for Ticket No" + receiptid
                };
                account.AmountE       = account.AmountE + receipt.Stake;
                statement.Transcation = "Teller Bet";
                statement.Method      = "Online";
                statement.Serial      = receiptid;

                branch.Balance = branch.Balance + Convert.ToDecimal(receipt.Stake);
                BetDatabase.Entry(branch).State = EntityState.Modified;
                BetDatabase.Accounts.AddOrUpdate(account);
                BetDatabase.Statements.Add(statement);
                await BetDatabase.SaveChangesAsync();

                var barcodeImage = bcg.CreateBarCode(receiptid);
                var tempPath     = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/BarCodes/" + receiptid.Trim() + ".png");
                try
                {
                    barcodeImage.Save(tempPath, ImageFormat.Png);
                }
                catch (Exception)
                {
                }
                response = ("Success");
            }
            else if (cost < 2000)
            {
                receipt.ReceiptId = 0;
                response          = ("Minimum betting stake is UGX 3000. Please enter amount more than UGX 2000.");
            }
            else
            {
                receipt.ReceiptId = 0;
                response          = ("Maximum stake is UGX " + bettingLimit + ". Please enter amount less than UGX " + bettingLimit + ".");
            }

            return(Ok(new { message = response, ReceiptNumber = receipt.ReceiptId, ReceiptTime = String.Format("{0:dd/MM/yyyy}", DateTime.Now) + " - " + toJavaScriptDate(DateTime.Now), TellerName = account.UserId, BranchName = branch.BranchName, Balance = account.AmountE, Serial = receiptid, FormatedSerial = GetSerialNumber(receiptid) }));
        }