public IActionResult AddBalance(decimal id, [FromBody] Balance balance)
        {
            //Created user's balance
            var            user_id     = User.FindFirst("userId")?.Value;
            DateTime       moment      = DateTime.Now;
            TblUserPosting userPosting = new TblUserPosting();
            var            role        = _context.TblUser.Where(a => a.UserId == id).First().RoleId;
            var            year        = moment.Year;
            var            month       = moment.Month;
            var            day         = moment.Day;
            var            hour        = moment.Hour;
            var            minute      = moment.Minute;
            var            second      = moment.Second;
            var            str         = "UB" + id.ToString() + role.ToString() + year.ToString() + month.ToString() + day.ToString() +
                                         hour.ToString() + minute.ToString() + second.ToString();

            userPosting.UserId            = id;
            userPosting.PostingNo         = str;
            userPosting.TransactionTypeId = 1;
            userPosting.Inward            = balance.Amount;
            userPosting.Outward           = 0;
            userPosting.Active            = true;
            userPosting.CreatedBy         = Decimal.Parse(user_id);
            userPosting.CreatedDate       = DateTime.Now;
            _context.TblUserPosting.Add(userPosting);
            _context.SaveChanges();

            //Created user' balance
            TblUserBalance userBalance = new TblUserBalance();

            userBalance.PostingNo         = str;
            userBalance.TransactionTypeId = 1;
            userBalance.UserId            = id;
            userBalance.Inward            = Convert.ToInt32(balance.Amount);
            userBalance.Outward           = 0;
            userBalance.CreatedDate       = DateTime.Now;
            _context.TblUserBalance.Add(userBalance);
            _context.SaveChanges();

            //Current logged user's balance
            DateTime       parent_moment      = DateTime.Now;
            TblUserPosting parent_userPosting = new TblUserPosting();
            var            parent_role        = _context.TblUser.Where(a => a.UserId == Decimal.Parse(user_id)).First().RoleId;
            var            parent_year        = parent_moment.Year;
            var            parent_month       = parent_moment.Month;
            var            parent_day         = parent_moment.Day;
            var            parent_hour        = parent_moment.Hour;
            var            parent_minute      = parent_moment.Minute;
            var            parent_second      = parent_moment.Second;
            var            parent_str         = "UB" + id.ToString() + parent_role.ToString() + parent_year.ToString() + parent_month.ToString() + parent_day.ToString() +
                                                parent_hour.ToString() + parent_minute.ToString() + parent_second.ToString();

            parent_userPosting.UserId            = Decimal.Parse(user_id);
            parent_userPosting.PostingNo         = parent_str;
            parent_userPosting.TransactionTypeId = 2;
            parent_userPosting.Inward            = 0;
            parent_userPosting.Outward           = balance.Amount;
            parent_userPosting.Active            = true;
            parent_userPosting.CreatedBy         = Decimal.Parse(user_id);
            parent_userPosting.CreatedDate       = DateTime.Now;
            _context.TblUserPosting.Add(parent_userPosting);
            _context.SaveChanges();

            //Current logged user's balance
            TblUserBalance parent_userBalance = new TblUserBalance();

            parent_userBalance.PostingNo         = parent_str;
            parent_userBalance.TransactionTypeId = 2;
            parent_userBalance.UserId            = Decimal.Parse(user_id);
            parent_userBalance.Inward            = 0;
            parent_userBalance.Outward           = Convert.ToInt32(balance.Amount);
            parent_userBalance.CreatedDate       = DateTime.Now;
            _context.TblUserBalance.Add(parent_userBalance);
            _context.SaveChanges();
            return(Ok(new { message = "Deposit Successfully" }));
        }
        public IActionResult BettingPost(UserBetting userBetting)
        {
            var         user_id     = User.FindFirst("userId")?.Value;
            TblGambling tblGambling = new TblGambling
            {
                PostingNo         = userBetting.PostingNo,
                TransactionTypeId = 10,
                GamblingTypeId    = userBetting.GamblingTypeId,
                EventId           = userBetting.EventId,
                RapidEventId      = userBetting.RapidEventId,
                TeamCount         = userBetting.TeamCount,
                Amount            = userBetting.Amount,
                UserId            = userBetting.UserId,
                Active            = true
            };

            _context.TblGambling.Add(tblGambling);
            _context.SaveChanges();
            var gamblingId = tblGambling.GamblingId;

            foreach (var item in userBetting.Details)
            {
                TblGamblingDetails gamblingDetails = new TblGamblingDetails
                {
                    GamblingId     = gamblingId,
                    LeagueId       = item.LeagueId,
                    FootballTeamId = item.FootballTeamId,
                    Under          = item.Under,
                    Overs          = item.Overs,
                    BodyOdd        = item.BodyOdd,
                    GoalOdd        = item.GoalOdd
                };
                _context.TblGamblingDetails.Add(gamblingDetails);
                _context.SaveChanges();
            }

            TblUserPosting userPosting = new TblUserPosting()
            {
                PostingNo         = userBetting.PostingNo,
                TransactionTypeId = 10,
                UserId            = userBetting.UserId,
                Inward            = 0,
                Outward           = userBetting.Amount,
                Active            = true,
                CreatedBy         = Decimal.Parse(user_id),
                CreatedDate       = DateTime.Now
            };

            _context.TblUserPosting.Add(userPosting);
            _context.SaveChanges();

            var            parentId           = _context.TblUser.Where(a => a.UserId == userBetting.UserId).First().CreatedBy;
            TblUserPosting parent_userPosting = new TblUserPosting()
            {
                PostingNo         = userBetting.PostingNo,
                TransactionTypeId = 9,
                UserId            = parentId,
                Inward            = userBetting.Amount,
                Outward           = 0,
                Active            = true,
                CreatedBy         = Decimal.Parse(user_id),
                CreatedDate       = DateTime.Now
            };

            _context.TblUserPosting.Add(parent_userPosting);
            _context.SaveChanges();

            return(Ok(new
            {
                message = "Betting Successfully"
            }));
        }
        public IActionResult CreditManage(decimal id, Credit creditAmount)
        {
            //Created user's credit
            var       user_id = User.FindFirst("userId")?.Value;
            TblCredit credit  = new TblCredit();
            DateTime  moment  = DateTime.Now;
            var       role    = _context.TblUser.Where(a => a.UserId == id).First().RoleId;
            var       year    = moment.Year;
            var       month   = moment.Month;
            var       day     = moment.Day;
            var       hour    = moment.Hour;
            var       minute  = moment.Minute;
            var       second  = moment.Second;
            var       str     = "CR" + id.ToString() + role.ToString() + year.ToString() + month.ToString() + day.ToString() +
                                hour.ToString() + minute.ToString() + second.ToString();

            credit.PostingNo         = str;
            credit.TransactionTypeId = 5;
            credit.UserId            = id;
            credit.Amount            = creditAmount.Amount;
            credit.Active            = true;
            credit.CreatedBy         = Decimal.Parse(user_id);
            credit.CreatedDate       = DateTime.Now;
            _context.TblCredit.Add(credit);
            _context.SaveChanges();

            //Current logged user's credit
            TblCredit parent_credit = new TblCredit();
            DateTime  parent_moment = DateTime.Now;
            var       parent_role   = _context.TblUser.Where(a => a.UserId == Decimal.Parse(user_id)).First().RoleId;
            var       parent_year   = moment.Year;
            var       parent_month  = moment.Month;
            var       parent_day    = moment.Day;
            var       parent_hour   = moment.Hour;
            var       parent_minute = moment.Minute;
            var       parent_second = moment.Second;
            var       parent_str    = "CR" + user_id.ToString() + parent_role.ToString() + parent_year.ToString() + parent_month.ToString() + parent_day.ToString() +
                                      parent_hour.ToString() + parent_minute.ToString() + parent_second.ToString();

            parent_credit.PostingNo         = parent_str;
            parent_credit.TransactionTypeId = 6;
            parent_credit.UserId            = Decimal.Parse(user_id);
            parent_credit.Amount            = creditAmount.Amount;
            parent_credit.Active            = true;
            parent_credit.CreatedBy         = Decimal.Parse(user_id);
            parent_credit.CreatedDate       = DateTime.Now;
            _context.TblCredit.Add(parent_credit);
            _context.SaveChanges();

            //Created user's credit
            TblUserPosting posting = new TblUserPosting();

            posting.PostingNo         = str;
            posting.TransactionTypeId = 5;
            posting.UserId            = id;
            posting.Inward            = creditAmount.Amount;
            posting.Outward           = 0;
            posting.Active            = true;
            posting.CreatedBy         = Decimal.Parse(user_id);
            posting.CreatedDate       = DateTime.Now;
            _context.TblUserPosting.Add(posting);
            _context.SaveChanges();

            //Current logged user's credit
            TblUserPosting parent_posting = new TblUserPosting();

            parent_posting.PostingNo         = parent_str;
            parent_posting.TransactionTypeId = 6;
            parent_posting.UserId            = Decimal.Parse(user_id);
            parent_posting.Inward            = 0;
            parent_posting.Outward           = creditAmount.Amount;
            parent_posting.Active            = true;
            parent_posting.CreatedBy         = Decimal.Parse(user_id);
            parent_posting.CreatedDate       = DateTime.Now;
            _context.TblUserPosting.Add(parent_posting);
            _context.SaveChanges();
            return(Ok());
        }