public ActionResult ChapterContents(int ID)
        {
            verifySessionforAdmin();

            if (Request.QueryString["ID"] != null)
            {
                QueryChapterContentID = Convert.ToInt32(Request.QueryString["ID"]);
            }
            if (ID > 0)
            {
                QueryChapterContentID = ID;
            }

            List <object> lstRet = new List <object>();

            lstRet = new SubjectsController().getChapterContentsByID(QueryChapterContentID);
            string ChapterName = "";
            string SubjectName = "";
            string SubjectType = "";

            if (lstRet.Count() > 0)
            {
                var ChapterContentBasic = lstRet.FirstOrDefault();
                ChapterName = Convert.ToString(ChapterContentBasic.GetType().GetProperty("ChapterName").GetValue(ChapterContentBasic));
                SubjectName = Convert.ToString(ChapterContentBasic.GetType().GetProperty("SubjectName").GetValue(ChapterContentBasic));
                SubjectType = Convert.ToString(ChapterContentBasic.GetType().GetProperty("SubjectType").GetValue(ChapterContentBasic));
            }

            ViewBag.SubjectsChaptersID = QueryChapterContentID;
            ViewBag.ChapterName        = ChapterName;
            ViewBag.SubjectName        = SubjectName;
            ViewBag.SubjectType        = SubjectType;
            if (lstRet != null && lstRet.Count == 1)
            {
                var ChapterContentBasic = lstRet.FirstOrDefault();
                var ContentsHolder      = Convert.ToString(ChapterContentBasic.GetType().GetProperty("ContentsHolder").GetValue(ChapterContentBasic));

                if (ContentsHolder == "0")
                {
                    lstRet.RemoveAt(0);
                }
            }


            ViewBag.ChapterContentsList = lstRet;

            return(View());
        }
        public ActionResult ChapterQuetionsEdit(int CHID, int SCID)
        {
            DataTable dt_1 = null;

            MSSQL_DAC clsDAC   = new MSSQL_DAC();
            Questions question = new Questions();


            dt_1 = clsDAC.Read_DT_Procedure("sp_GetSubjectsChapterQuestionsByQuestionID", new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("QuestionID", CHID)
            });


            if (dt_1 != null || dt_1.Rows.Count > 0)
            {
                foreach (DataRow dr_1 in dt_1.Rows)
                {
                    question.QuestionID         = Convert.ToInt32(dr_1["QuestionID"]);
                    question.URL                = dr_1["URL"] == DBNull.Value ? "" : Convert.ToString(dr_1["URL"]);
                    question.SubjectsChaptersID = (dr_1["SubjectsChaptersID"] == DBNull.Value ? 0 : Convert.ToInt32(dr_1["SubjectsChaptersID"]));
                    question.QuestionText       = dr_1["QuestionText"] == DBNull.Value ? "" : Convert.ToString(dr_1["QuestionText"]);
                    question.ImageFileName      = dr_1["ImageFileName"] == DBNull.Value ? "" : Convert.ToString(dr_1["ImageFileName"]);
                    question.VideoFileName      = dr_1["VideoFileName"] == DBNull.Value ? "" : Convert.ToString(dr_1["VideoFileName"]);
                    question.PaperYear          = dr_1["PaperYear"] == DBNull.Value ? "" : Convert.ToString(dr_1["PaperYear"]);
                    question.ImageFilePath      = dr_1["ImageFilePath"] == DBNull.Value ? "" : Convert.ToString(dr_1["ImageFilePath"]);
                    question.PdfDocFile         = dr_1["PdfDocFile"] == DBNull.Value ? "" : Convert.ToString(dr_1["PdfDocFile"]);
                    question.PdfDocFilePath     = dr_1["PdfDocFilePath"] == DBNull.Value ? "" : Convert.ToString(dr_1["PdfDocFilePath"]);
                    question.VideoFilePath      = dr_1["VideoFilePath"] == DBNull.Value ? "" : Convert.ToString(dr_1["VideoFilePath"]);
                    question.isfree             = Convert.ToBoolean(dr_1["Isfree"]);
                }
            }

            List <object> lstRet = new List <object>();

            lstRet = new SubjectsController().getChapterContentsByID(SCID);
            string ChapterName = "";
            string SubjectName = "";
            string SubjectType = "";

            if (lstRet.Count() > 0)
            {
                var ChapterContentBasic = lstRet.FirstOrDefault();
                ChapterName = Convert.ToString(ChapterContentBasic.GetType().GetProperty("ChapterName").GetValue(ChapterContentBasic));
                SubjectName = Convert.ToString(ChapterContentBasic.GetType().GetProperty("SubjectName").GetValue(ChapterContentBasic));
                SubjectType = Convert.ToString(ChapterContentBasic.GetType().GetProperty("SubjectType").GetValue(ChapterContentBasic));
            }

            ViewBag.SubjectsChaptersID = SCID;
            ViewBag.ChapterName        = ChapterName;
            ViewBag.SubjectName        = SubjectName;
            ViewBag.SubjectType        = SubjectType;


            return(View(question));
        }
        public ActionResult ChapterContents(FormCollection frmCollection, int ID = 0, int page = 1)
        {
            verifySessionforAdmin();
            var ImageFileName = ""; //using this field to save variant value
            var VideoFileName = "";
            var PdfFileName   = "";

            var ImageFilePath = "";
            var VideoFilePath = "";
            var PdfFilePath   = "";
            var isfree        = false;
            var PaperYear     = "";



            MSSQL_DAC clsDAC = null;

            clsDAC = new MSSQL_DAC();
            List <string> FilesAlreadyLoaded = new List <string>();
            int           SubjectChapterID   = 0;

            isfree = Convert.ToBoolean(frmCollection["Isfree"]);
            Int32.TryParse(Convert.ToString(frmCollection["SubjectChapterID"]), out SubjectChapterID);

            if (!string.IsNullOrEmpty(frmCollection["PaperYear"]))
            {
                PaperYear = Convert.ToString(frmCollection["PaperYear"]);
            }
            if (!string.IsNullOrEmpty(frmCollection["QuestionDiagram"]))
            {
                ImageFileName = Convert.ToString(frmCollection["QuestionDiagram"]);
            }
            if (Request.Files.Count > 0)
            {
                for (int updFile = 0; updFile < Request.Files.Count; updFile++)
                {
                    //string ContentFileName = Convert.ToString(dt_1.Rows[0]["ContentFileName"]);
                    var supportedFile             = false;
                    HttpPostedFileBase postedFile = Request.Files[updFile];
                    var         fileName          = postedFile.FileName;
                    var         fileExtension     = System.IO.Path.GetExtension(fileName).ToLower();
                    System.Guid Guid    = System.Guid.NewGuid();
                    var         guidStr = Guid.ToString() + fileExtension;

                    if (fileExtension == ".mp4")
                    {
                        supportedFile = true;
                        VideoFileName = fileName;
                        VideoFilePath = guidStr;
                    }
                    //else if (fileExtension == ".png" || fileExtension == ".jpg" || fileExtension == ".jpeg")
                    //{
                    //    supportedFile = true;
                    //    ImageFileName = fileName;
                    //    ImageFilePath = guidStr;
                    //}
                    else if (fileExtension == ".pdf")
                    {
                        supportedFile = true;
                        PdfFileName   = fileName;
                        PdfFilePath   = guidStr;
                    }

                    if (supportedFile)
                    {
                        fileName = guidStr; //System.IO.Path.GetFileName(fileName);
                        System.IO.MemoryStream mem = new System.IO.MemoryStream();
                        var path = System.IO.Path.Combine(Server.MapPath("~/ContentStorage/ChaptersContents/"), fileName);
                        //    postedFile.InputStream.CopyTo(mem);
                        //    System.IO.File.WriteAllBytes(System.IO.Path.Combine(Server.MapPath("~/ContentStorage/ChaptersContents/"), fileName), mem.ToArray());
                        //
                        postedFile.SaveAs(path);
                    }
                }
            }


            {
                List <KeyValuePair <string, object> > lstData = new List <KeyValuePair <string, object> >()
                {
                    new KeyValuePair <string, object>("SubjectsChaptersID", SubjectChapterID),
                    new KeyValuePair <string, object>("Url", frmCollection["youTubeUrl"]),
                    new KeyValuePair <string, object>("CreatedBy", Session["UserID"]),
                    new KeyValuePair <string, object>("QuestionText", frmCollection["questionText"]),
                    new KeyValuePair <string, object>("ImageFileName", ImageFileName),
                    new KeyValuePair <string, object>("VideoFileName", VideoFileName),
                    new KeyValuePair <string, object>("PaperYear", PaperYear),
                    new KeyValuePair <string, object>("PdfDocFile", PdfFileName),
                    new KeyValuePair <string, object>("ImageFilePath", ImageFilePath),
                    new KeyValuePair <string, object>("VideoFilePath", VideoFilePath),
                    new KeyValuePair <string, object>("PdfDocFilePath", PdfFilePath),
                    new KeyValuePair <string, object>("Isfree", isfree),
                };

                DataTable dt_1 = clsDAC.Read_DT_Procedure("sp_SaveChaptersQuestions", lstData);
                ViewBag.Error = clsDAC.Error_Message;
            }
            //if (Request.Files.Count > 0)
            //{
            //    for (int updFile = 0; updFile < Request.Files.Count; updFile++)
            //    {
            //        List<KeyValuePair<string, object>> lstData = new List<KeyValuePair<string, object>>()
            //        {
            //        new KeyValuePair<string,object>("SubjectsChaptersID",SubjectChapterID),
            //        new KeyValuePair<string,object>("OriginalFileName",Request.Files[updFile].FileName),
            //        new KeyValuePair<string,object>("CreatedBy",Session["UserID"])
            //        };

            //        DataTable dt_1 = clsDAC.Read_DT_Procedure("sp_SaveChaptersContents", lstData);
            //        ViewBag.Error = clsDAC.Error_Message;

            //        if (dt_1 != null || dt_1.Rows.Count > 0)
            //        {
            //            if (Convert.ToBoolean(dt_1.Rows[0]["IsAlreadyLoaded"]))
            //            {
            //                FilesAlreadyLoaded.Add(Convert.ToString(dt_1.Rows[0]["OriginalFileName"]));
            //            }
            //            else
            //            {
            //                string ContentFileName = Convert.ToString(dt_1.Rows[0]["ContentFileName"]);
            //                HttpPostedFileBase postedFile = Request.Files[updFile];
            //                System.IO.MemoryStream mem = new System.IO.MemoryStream();
            //                postedFile.InputStream.CopyTo(mem);
            //                System.IO.File.WriteAllBytes(Server.MapPath("/ContentStorage/ChaptersContents/") + ContentFileName, mem.ToArray());
            //            }
            //        }
            //    }
            //}


            List <object> lstRet = new List <object>();

            lstRet = new SubjectsController().getChapterContentsByID(SubjectChapterID);
            string ChapterName = "";
            string SubjectName = "";

            if (lstRet.Count() > 0)
            {
                var ChapterContentBasic = lstRet.FirstOrDefault();
                ChapterName = Convert.ToString(ChapterContentBasic.GetType().GetProperty("ChapterName").GetValue(ChapterContentBasic));
                SubjectName = Convert.ToString(ChapterContentBasic.GetType().GetProperty("SubjectName").GetValue(ChapterContentBasic));
            }

            ViewBag.SubjectsChaptersID  = SubjectChapterID;
            ViewBag.ChapterName         = ChapterName;
            ViewBag.SubjectName         = SubjectName;
            ViewBag.ChapterContentsList = lstRet;
            ViewBag.FilesAlreadyLoaded  = FilesAlreadyLoaded;
            ViewBag.SubjectsChaptersID  = ID;

            //////////Response.Redirect(string.Format("~/Chapters/ChapterContents?ID={0}", SubjectChapterID));
            ////RedirectToAction(string.Format("ChapterContents?ID={0}", SubjectChapterID));
            //   return View(SubjectChapterID);
            return(RedirectToAction("ChapterContents", new { ID = SubjectChapterID }));
        }
        //  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));
        }