public ActionResult Index()
        {
            verifySessionforAdmin();


            List <Subjects>       lstSubject          = new SubjectsController().getSubjects();
            List <SelectListItem> lstSubjectsDropDown = new List <SelectListItem>();
            var varlstSubject = lstSubject.Select(item => new { item.SubjectName, item.SubjectID });

            lstSubjectsDropDown.Add(new SelectListItem()
            {
                Text = "Select Subject", Value = "0"
            });
            foreach (var item in varlstSubject)
            {
                lstSubjectsDropDown.Add(new SelectListItem()
                {
                    Text = item.SubjectName, Value = item.SubjectID.ToString()
                });
            }


            ViewBag.SubjectLookup = lstSubjectsDropDown;
            return(View());
        }
        //  public ActionResult ShowVideo(int SubChapID, string name)
        public ActionResult ShowVideo(int SubChapID, int questionId, int exerciseId, string transactionid
                                      , string session_id = null, bool isdwn = false
                                      )
        {
            if (TempData["paymentTransactionId"] != null)
            {
                PayPalManager payPalManager = new PayPalManager();
                var           invoice       = payPalManager.GetPayPalInvoiceByGUID(Convert.ToString(TempData["paymentTransactionId"]));
                if (invoice != null)
                {
                    if (invoice.QuestionID != SubChapID)
                    {
                        ViewBag.paymentTransactionId = null;
                    }
                    else
                    {
                        ViewBag.paymentTransactionId = TempData["paymentTransactionId"];
                    }
                }
                //TempData.Keep("paymentTransactionId");
            }
            if (string.IsNullOrEmpty(transactionid))
            {
                if (isdwn == true)
                {
                    List <Questions> Question = new SubjectsController().getChaptersQuesionsByQuestionID(questionId);
                    if (Question.Select(x => x.isfree).FirstOrDefault() == true)
                    {
                        var showVideoViewModel1 = new SubjectsController().getShowVideoViewModelByID(SubChapID).FirstOrDefault();
                        var Exercises1          = new SubjectsController().getShowVideoViewModelByID(exerciseId);
                        var question1           = Exercises1.Where(x => x.ContentsHolder == questionId).FirstOrDefault();
                        ViewBag.Path = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(question1.VideoFilePath);
                        showVideoViewModel1.ExerciseName = Exercises1.FirstOrDefault().ChapterName;
                        showVideoViewModel1.QuestionText = question1.QuestionText;

                        string downloadURL1 = GetBaseUrl() + "/Home/DownloadQuestion?p1=" + questionId;
                        ViewBag.DownloadURL   = downloadURL1;
                        ViewBag.transactionid = transactionid;


                        return(View("ShowVideo", "~/Views/Shared/_IndexPageLayout.cshtml", showVideoViewModel1));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    return
                        (RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                PayPalManager payPalManager = new PayPalManager();
                var           invoice       = payPalManager.GetPayPalInvoiceByGUID(transactionid);
                if (invoice != null && invoice.RequestXML.ToLower().Contains("stripe payment"))
                {
                    if (invoice.QuestionID != questionId && session_id != invoice.PaymentID)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    if (invoice == null || invoice.QuestionID != questionId || invoice.State != "approved")
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            var showVideoViewModel = new SubjectsController().getShowVideoViewModelByID(SubChapID).FirstOrDefault();
            var Exercises          = new SubjectsController().getShowVideoViewModelByID(exerciseId);
            var question           = Exercises.Where(x => x.ContentsHolder == questionId).FirstOrDefault();

            ViewBag.Path = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(question.VideoFilePath);
            showVideoViewModel.ExerciseName = Exercises.FirstOrDefault().ChapterName;
            showVideoViewModel.QuestionText = question.QuestionText;

            string downloadURL = GetBaseUrl() + "/Home/DownloadQuestion?p1=" + questionId;

            ViewBag.DownloadURL   = downloadURL;
            ViewBag.transactionid = transactionid;

            try
            {
                string strURL = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(question.VideoFilePath);
                //string strFileName = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(videoFileName);
                WebClient    req      = new WebClient();
                HttpResponse response = System.Web.HttpContext.Current.Response;
                response.Clear();
                response.ClearContent();
                response.ClearHeaders();
                response.Buffer = true;
                response.AddHeader("Content-Disposition", "attachment;filename=\"" + Server.MapPath(strURL) + "\"");
                //response.AppendHeader("Content-Disposition", "attachment; filename=" + subjectName +" "+ chapterName + " " + questionText + "");
                byte[] data = req.DownloadData(Server.MapPath(strURL));
                response.BinaryWrite(data);
                response.End();
            }
            catch (Exception ex)
            {
            }

            return(View("ShowVideo", "~/Views/Shared/_IndexPageLayout.cshtml", showVideoViewModel));
        }
        public ActionResult ShowVideoPastPaper(int subID, int questionId, string transactionid, string session_id = null, bool isdwn = false, string variant = null)
        {
            if (TempData["paymentTransactionId"] != null)
            {
                PayPalManager payPalManager = new PayPalManager();
                var           invoice       = payPalManager.GetPayPalInvoiceByGUID(Convert.ToString(TempData["paymentTransactionId"]));
                if (invoice != null)
                {
                    if (invoice.QuestionID != subID)
                    {
                        ViewBag.paymentTransactionId = null;
                    }
                    else if (invoice.QuestionID == subID || variant != null)
                    {
                        List <QuestionPayment> lstQuestion = new SubjectsController().getQuesionsFromPaymentQuestion_BySubjectsIDAndTransactionAndVarient(subID, Convert.ToString(TempData["paymentTransactionId"]), variant);
                        if (lstQuestion.Count > 0)
                        {
                            if (lstQuestion.Select(x => x.create_date == DateTime.Now.Date).FirstOrDefault())
                            {
                                ViewBag.paymentTransactionId = TempData["paymentTransactionId"];
                                TempData.Keep("paymentTransactionId");
                            }
                            else
                            {
                                ViewBag.paymentTransactionId = null;
                            }
                        }
                        else
                        {
                            ViewBag.paymentTransactionId = null;
                        }
                    }
                    else
                    {
                        List <QuestionPayment> lstQuestion = new SubjectsController().getQuesionsFromPaymentQuestion_BySubjectsIDAndTransaction(subID, Convert.ToString(TempData["paymentTransactionId"]));
                        if (lstQuestion.Count > 0)
                        {
                            if (lstQuestion.Select(x => x.create_date == DateTime.Now.Date).FirstOrDefault())
                            {
                                ViewBag.paymentTransactionId = TempData["paymentTransactionId"];
                                TempData.Keep("paymentTransactionId");
                            }
                            else
                            {
                                ViewBag.paymentTransactionId = null;
                            }
                        }
                        else
                        {
                            ViewBag.paymentTransactionId = null;
                        }
                    }
                }
            }
            if (string.IsNullOrEmpty(transactionid))
            {
                if (isdwn == true)
                {
                    List <Questions> Question = new SubjectsController().getChaptersQuesionsByQuestionID(questionId);
                    if (Question.Select(x => x.isfree).FirstOrDefault() == true)
                    {
                        List <object> lstRet1             = new SubjectsController().getChapterContentsQuestionBySubjectID(subID);
                        var           showVideoViewModel1 = new ShowVideoViewModel();
                        var           videoFileName1      = "";
                        var           videoFilePath1      = "";
                        var           subjectName1        = "";
                        var           chapterName1        = "";
                        var           questionText1       = "";

                        foreach (var item in lstRet1)
                        {
                            var questionIdDB = item.GetType().GetProperty("ContentsHolder").GetValue(item, null).ToString();

                            if (questionId.ToString() == questionIdDB)
                            {
                                videoFilePath1 = item.GetType().GetProperty("VideoFilePath").GetValue(item, null).ToString();
                                videoFileName1 = item.GetType().GetProperty("VideoFileName").GetValue(item, null).ToString();
                                subjectName1   = item.GetType().GetProperty("SubjectName").GetValue(item, null).ToString();
                                chapterName1   = item.GetType().GetProperty("ChapterName").GetValue(item, null).ToString();
                                questionText1  = item.GetType().GetProperty("QuestionText").GetValue(item, null).ToString();
                            }
                        }

                        ViewBag.Path = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(videoFilePath1);


                        showVideoViewModel1.SubjectName = subjectName1;
                        showVideoViewModel1.ChapterName = chapterName1;

                        showVideoViewModel1.ExerciseName = chapterName1;
                        showVideoViewModel1.QuestionText = questionText1;

                        ViewBag.ShowVideoPastPaper = 1;

                        string downloadURL1 = GetBaseUrl() + "/Home/DownloadQuestion?p1=" + questionId;
                        ViewBag.DownloadURL   = downloadURL1;
                        ViewBag.transactionid = transactionid;

                        try
                        {
                            string       strURL      = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(videoFilePath1);
                            string       strFileName = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(videoFileName1);
                            WebClient    req         = new WebClient();
                            HttpResponse response    = System.Web.HttpContext.Current.Response;
                            response.Clear();
                            response.ClearContent();
                            response.ClearHeaders();
                            response.Buffer = true;
                            response.AddHeader("Content-Disposition", "attachment;filename=\"" + Server.MapPath(videoFileName1) + "\"");
                            //response.AppendHeader("Content-Disposition", "attachment; filename=" + subjectName +" "+ chapterName + " " + questionText + "");
                            byte[] data = req.DownloadData(Server.MapPath(strURL));
                            response.BinaryWrite(data);
                            response.End();
                        }
                        catch (Exception ex)
                        {
                        }

                        return(View("ShowVideo", "~/Views/Shared/_IndexPageLayout.cshtml", showVideoViewModel1));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            else
            {
                PayPalManager payPalManager = new PayPalManager();
                var           invoice       = payPalManager.GetPayPalInvoiceByGUID(transactionid);

                //if (invoice == null || invoice.QuestionID != questionId || invoice.State != "approved")
                //    return RedirectToAction("Index", "Home");

                if (invoice != null && invoice.RequestXML.ToLower().Contains("stripe payment"))
                {
                    //if (invoice.QuestionID != questionId && session_id != invoice.PaymentID)
                    if (invoice.PaymentID == null)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    //if (invoice == null || invoice.QuestionID != questionId || invoice.State != "approved")
                    if (invoice == null || invoice.State != "approved")
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            List <object> lstRet             = new SubjectsController().getChapterContentsQuestionBySubjectID(subID);
            var           showVideoViewModel = new ShowVideoViewModel();
            var           videoFileName      = "";
            var           videoFilePath      = "";
            var           subjectName        = "";
            var           chapterName        = "";
            var           questionText       = "";

            foreach (var item in lstRet)
            {
                var questionIdDB = item.GetType().GetProperty("ContentsHolder").GetValue(item, null).ToString();

                if (questionId.ToString() == questionIdDB)
                {
                    videoFilePath = item.GetType().GetProperty("VideoFilePath").GetValue(item, null).ToString();
                    videoFileName = item.GetType().GetProperty("VideoFileName").GetValue(item, null).ToString();
                    subjectName   = item.GetType().GetProperty("SubjectName").GetValue(item, null).ToString();
                    chapterName   = item.GetType().GetProperty("ChapterName").GetValue(item, null).ToString();
                    questionText  = item.GetType().GetProperty("QuestionText").GetValue(item, null).ToString();
                }
            }

            ViewBag.Path = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(videoFilePath);


            showVideoViewModel.SubjectName = subjectName;
            showVideoViewModel.ChapterName = chapterName;

            showVideoViewModel.ExerciseName = chapterName;
            showVideoViewModel.QuestionText = questionText;

            ViewBag.ShowVideoPastPaper = 1;

            string downloadURL = GetBaseUrl() + "/Home/DownloadQuestion?p1=" + questionId;

            ViewBag.DownloadURL   = downloadURL;
            ViewBag.transactionid = transactionid;

            try
            {
                string       strURL      = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(videoFilePath);
                string       strFileName = "/ContentStorage/ChaptersContents/" + System.IO.Path.GetFileName(videoFileName);
                WebClient    req         = new WebClient();
                HttpResponse response    = System.Web.HttpContext.Current.Response;
                response.Clear();
                response.ClearContent();
                response.ClearHeaders();
                response.Buffer = true;
                response.AddHeader("Content-Disposition", "attachment;filename=\"" + Server.MapPath(videoFileName) + "\"");
                //response.AppendHeader("Content-Disposition", "attachment; filename=" + subjectName +" "+ chapterName + " " + questionText + "");
                byte[] data = req.DownloadData(Server.MapPath(strURL));
                response.BinaryWrite(data);
                response.End();
            }
            catch (Exception ex)
            {
            }

            return(View("ShowVideo", "~/Views/Shared/_IndexPageLayout.cshtml", showVideoViewModel));
        }
        public ActionResult ChapterQuestions(int Sub, int questionYearId, string variant, bool scfp = false)
        {
            ChaptersViewModel vm            = new ChaptersViewModel();
            PayPalManager     payPalManager = new PayPalManager();
            int subjecttype;

            if (scfp == false)
            {
                if (TempData["paymentTransactionId"] != null)
                {
                    SubjectsController sc = new SubjectsController();
                    sc.DeleteInvoiceFromPaymentQuestion(Convert.ToString(TempData["paymentTransactionId"]));
                    payPalManager.DeletePayPalInvoice(Convert.ToString(TempData["paymentTransactionId"]));

                    ViewBag.paymentTransactionId     = null;
                    TempData["paymentTransactionId"] = null;
                }
                else if (TempData["paymentTransactionId"] == null)
                {
                    ViewBag.paymentTransactionId     = null;
                    TempData["paymentTransactionId"] = null;
                }
            }

            if (TempData["paymentTransactionId"] != null)
            {
                var invoice = payPalManager.GetPayPalInvoiceByGUID(Convert.ToString(TempData["paymentTransactionId"]));
                if (invoice != null)
                {
                    if (invoice.QuestionID != Sub)
                    {
                        ViewBag.paymentTransactionId = null;
                    }
                    else if (invoice.QuestionID == Sub && !string.IsNullOrEmpty(variant))
                    {
                        List <QuestionPayment> lstQuestion = new SubjectsController().getQuesionsFromPaymentQuestion_BySubjectsIDAndTransactionAndVarient(Sub, Convert.ToString(TempData["paymentTransactionId"]), variant);
                        if (lstQuestion.Count > 0)
                        {
                            if (lstQuestion.Select(x => x.create_date == DateTime.Now.Date).FirstOrDefault())
                            {
                                ViewBag.paymentTransactionId = TempData["paymentTransactionId"];
                                TempData.Keep("paymentTransactionId");

                                //try
                                //{
                                //    MailMessage msgs = new MailMessage();
                                //    msgs.To.Add("*****@*****.**");
                                //    MailAddress address = new MailAddress("*****@*****.**");
                                //    msgs.From = address;
                                //    msgs.Subject = "USer Redirect to Payment";
                                //    string htmlBody = "Sending This email When user click on Payment Button ";
                                //    msgs.Body = htmlBody;
                                //    msgs.IsBodyHtml = true;
                                //    SmtpClient client = new SmtpClient();
                                //    client.Host = "relay-hosting.secureserver.net";
                                //    client.Port = 25;
                                //    client.UseDefaultCredentials = false;
                                //    client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "asjad001$");
                                //    //Send the msgs
                                //    client.Send(msgs);

                                //}
                                //catch (Exception ex) { }
                            }
                            else
                            {
                                ViewBag.paymentTransactionId = null;
                            }
                        }
                        else
                        {
                            ViewBag.paymentTransactionId = null;
                        }
                    }
                    else
                    {
                        List <QuestionPayment> lstQuestion = new SubjectsController().getQuesionsFromPaymentQuestion_BySubjectsIDAndTransaction(Sub, Convert.ToString(TempData["paymentTransactionId"]));
                        if (lstQuestion.Count > 0)
                        {
                            if (lstQuestion.Select(x => x.create_date == DateTime.Now.Date).FirstOrDefault())
                            {
                                ViewBag.paymentTransactionId = TempData["paymentTransactionId"];
                                TempData.Keep("paymentTransactionId");
                                //try
                                //{
                                //    MailMessage msgs = new MailMessage();
                                //    msgs.To.Add("*****@*****.**");
                                //    MailAddress address = new MailAddress("*****@*****.**");
                                //    msgs.From = address;
                                //    msgs.Subject = "USer Redirect to Payment";
                                //    string htmlBody = "Sending This email When user click on Payment Button ";
                                //    msgs.Body = htmlBody;
                                //    msgs.IsBodyHtml = true;
                                //    SmtpClient client = new SmtpClient();
                                //    client.Host = "relay-hosting.secureserver.net";
                                //    client.Port = 25;
                                //    client.UseDefaultCredentials = false;
                                //    client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "asjad001$");
                                //    //Send the msgs
                                //    client.Send(msgs);

                                //}
                                //catch (Exception ex) { }
                            }
                            else
                            {
                                ViewBag.paymentTransactionId = null;
                            }
                        }
                        else
                        {
                            ViewBag.paymentTransactionId = null;
                        }
                    }
                }
                else
                {
                    ViewBag.paymentTransactionId = null;
                }
            }
            else
            {
                ViewBag.paymentTransactionId = null;
            }



            List <SubjectChapters> lstRet  = new SubjectsController().getChaptersExerciseBySubjectsID(Sub);
            List <Questions>       lstRet1 = new SubjectsController().getChaptersQuesionsBySubjectsID(Sub);
            var variants1 = lstRet1.Where(x => !string.IsNullOrWhiteSpace(x.ImageFileName)).Select(x => x.ImageFileName).Distinct().ToList();

            subjecttype             = lstRet.Select(x => x.SubjectType).FirstOrDefault();
            ViewBag.subjecttype     = subjecttype;
            ViewBag.selectedVariant = null;

            // var type = lstsubjects.Select(x=>x.SubjectID) lstRet1.Select(x => x.SubjectsChaptersID).FirstOrDefault();
            vm.Variants = GetSelectListItems(variants1);
            var questionYear = lstRet1.Where(x => x.QuestionID == questionYearId).FirstOrDefault()?.PaperYear;

            //var questionYear = lstRet1.FirstOrDefault()?.PaperYear;
            ViewBag.questionYearId = questionYearId;


            //var variatnEndwith2;
            //foreach
            if (subjecttype == 1 || subjecttype == 4 || subjecttype == 5 || subjecttype == 8)
            {
                if (!string.IsNullOrEmpty(variant))
                {
                    lstRet1 = lstRet1.Where(x => x.ImageFileName == variant).ToList();
                    ViewBag.selectedVariant = variant;
                }
                else
                {
                    var variants2 = variants1.Where(x => x.EndsWith("2")).FirstOrDefault();
                    lstRet1 = lstRet1.Where(x => x.ImageFileName == variants2).ToList();
                    ViewBag.selectedVariant = variants2;
                }
            }



            vm.SubjectChapters = lstRet;
            vm.Questions       = lstRet1.Where(x => x.PaperYear == questionYear).ToList();

            return(View(vm));
        }