public ActionResult Chapters(int Sub, int IsTopical)
        {
            ChaptersViewModel vm = new ChaptersViewModel();

            List <SubjectChapters> lstRet  = new SubjectsController().getChaptersExerciseBySubjectsID(Sub);
            List <Questions>       lstRet1 = new SubjectsController().getChaptersQuesionsBySubjectsID(Sub);

            vm.SubjectChapters = lstRet;
            vm.Questions       = lstRet1;

            ViewBag.IsTopical = IsTopical;

            return(View(vm));
        }
 public ChaptersController(ApplicationDbContext context)
 {
     _context   = context;
     ChaptersVM = new ChaptersViewModel()
     {
         Chapter  = new Chapter(),
         Book     = new Book(),
         Censor   = new ApplicationUser(),
         Chapters = new List <Chapter>()
     };
     BooksVM = new BooksViewModel()
     {
         Chapter = new Chapter()
     };
 }
        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));
        }