// GET: Subjects/Create
        public ActionResult Create()
        {
            verifySessionforAdmin();
            Subjects modelSubjects = new Subjects();
            IEnumerable <SelectListItem> ddlSubjectType    = null;
            IEnumerable <SelectListItem> ddlparentSubjects = null;
            MSSQL_DAC clsDAC = null;

            clsDAC = new MSSQL_DAC();

            DataTable dt_1 = clsDAC.Read_DT_Query("SELECT ValueColumn,DisplayColumn FROM dbo.tblLookups WHERE LookupCode='SubjectType'");

            if (dt_1 != null)
            {
                ddlSubjectType = dt_1.Rows.Cast <DataRow>().ToList().Select(x => new SelectListItem()
                {
                    Value = Convert.ToString(x["ValueColumn"]), Text = Convert.ToString(x["DisplayColumn"])
                });
            }

            dt_1 = clsDAC.Read_DT_Query("SELECT SubjectID, SubjectName FROM dbo.tblSubjects WHERE SubjectType <> 8 AND ISNULL(IsActive,1) = 1");
            if (dt_1 != null)
            {
                ddlparentSubjects = dt_1.Rows.Cast <DataRow>().ToList().Select(x => new SelectListItem()
                {
                    Value = Convert.ToString(x["SubjectID"]), Text = Convert.ToString(x["SubjectName"])
                });
            }


            ViewBag.MainModel             = modelSubjects;
            ViewBag.ddSubjectTypelist     = ddlSubjectType;
            ViewBag.ddlparentSubjectslist = ddlparentSubjects;
            return(View());
        }
        public ActionResult AboutUs()
        {
            List <object> lstVisitors = new List <object>();
            DataTable     dt_1        = null;
            MSSQL_DAC     clsDAC      = null;

            clsDAC = new MSSQL_DAC();
            dt_1   = clsDAC.Read_DT_Query("SELECT Id,VisitingTime FROM tblVisitor");

            if (dt_1 != null || dt_1.Rows.Count != 0)
            {
                foreach (DataRow item in dt_1.Rows)
                {
                    lstVisitors.Add(new { ID = Convert.ToInt32(item["Id"]), VisitingTime = Convert.ToDateTime(item["VisitingTime"]) });
                }
            }

            return(View(lstVisitors));
        }
        public ActionResult Create(FormCollection collection)
        {
            Subjects modelSubject = null;
            IEnumerable <SelectListItem> ddlSubjectType    = null;
            IEnumerable <SelectListItem> ddlparentSubjects = null;
            MSSQL_DAC clsDAC = null;

            clsDAC = new MSSQL_DAC();

            DataTable dt_1 = clsDAC.Read_DT_Query("SELECT ValueColumn,DisplayColumn FROM dbo.tblLookups WHERE LookupCode='SubjectType'");

            if (dt_1 != null)
            {
                ddlSubjectType = dt_1.Rows.Cast <DataRow>().ToList().Select(x => new SelectListItem()
                {
                    Value = Convert.ToString(x["ValueColumn"]), Text = Convert.ToString(x["DisplayColumn"])
                });
            }

            dt_1 = clsDAC.Read_DT_Query("SELECT SubjectID, SubjectName FROM dbo.tblSubjects WHERE SubjectType <> 8 AND ISNULL(IsActive,1) = 1");
            if (dt_1 != null)
            {
                ddlparentSubjects = dt_1.Rows.Cast <DataRow>().ToList().Select(x => new SelectListItem()
                {
                    Value = Convert.ToString(x["SubjectID"]), Text = Convert.ToString(x["SubjectName"])
                });
                ddlparentSubjects.ToList().Insert(0, new SelectListItem()
                {
                    Value = "0", Text = "Select Subject"
                });
            }


            try
            {
                modelSubject = new Subjects()
                {
                    SubjectCode     = collection["SubjectCode"],
                    SubjectName     = collection["SubjectName"],
                    SubjectType     = Convert.ToInt32(collection["modelSubject.SubjectType"]),
                    SubjectYear     = collection["SubjectYear"],
                    ParentSubjectID = (string.IsNullOrEmpty(collection["modelSubject.ParentSubjectID"]) ? 0 : Convert.ToInt32(collection["modelSubject.ParentSubjectID"]))
                };

                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase     postedFile = Request.Files[0];
                    System.IO.MemoryStream mem        = new System.IO.MemoryStream();
                    postedFile.InputStream.CopyTo(mem);
                    modelSubject.SubjectImage = mem.ToArray();
                }

                clsDAC = new MSSQL_DAC();

                List <KeyValuePair <string, object> > lstData = new List <KeyValuePair <string, object> >()
                {
                    new KeyValuePair <string, object>("SubjectName", modelSubject.SubjectName),
                    new KeyValuePair <string, object>("SubjectCode", modelSubject.SubjectCode),
                    new KeyValuePair <string, object>("SubjectType", modelSubject.SubjectType),
                    new KeyValuePair <string, object>("SubjectYear", modelSubject.SubjectYear),
                    new KeyValuePair <string, object>("ParentSubjectID", modelSubject.ParentSubjectID),
                    new KeyValuePair <string, object>("SubjectImage", modelSubject.SubjectImage),
                    new KeyValuePair <string, object>("CreatedBy", Session["UserID"])
                };

                clsDAC.Execute_Procedure("sp_CreateSubjects", lstData);

                ViewBag.Error = clsDAC.Error_Message;

                if (clsDAC.Error_Message.Trim() == "")
                {
                    Response.Redirect("~/Subjects/List");
                }

                ViewBag.MainModel             = modelSubject;
                ViewBag.ddSubjectTypelist     = ddlSubjectType;
                ViewBag.ddlparentSubjectslist = ddlparentSubjects;
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            ViewBag.MainModel             = modelSubject;
            ViewBag.ddSubjectTypelist     = ddlSubjectType;
            ViewBag.ddlparentSubjectslist = ddlparentSubjects;
            return(View());
        }
        // GET: Subjects/Edit/5
        public ActionResult Edit(int id)
        {
            verifySessionforAdmin();

            Subjects modelSubjects = new Subjects();
            IEnumerable <SelectListItem> ddlSubjectType       = null;
            List <SelectListItem>        slstSubjectTypeRet   = new List <SelectListItem>();
            IEnumerable <SelectListItem> ddlparentSubjects    = null;
            List <SelectListItem>        slstParentSubjectRet = new List <SelectListItem>();
            MSSQL_DAC clsDAC = null;

            clsDAC = new MSSQL_DAC();

            DataTable dt_1 = clsDAC.Read_DT_Query("SELECT ValueColumn,DisplayColumn FROM dbo.tblLookups WHERE LookupCode='SubjectType'");

            if (dt_1 != null)
            {
                ddlSubjectType = dt_1.Rows.Cast <DataRow>().ToList().Select(x => new SelectListItem()
                {
                    Value = Convert.ToString(x["ValueColumn"]), Text = Convert.ToString(x["DisplayColumn"])
                });
            }

            dt_1 = clsDAC.Read_DT_Query("SELECT SubjectID, SubjectName FROM dbo.tblSubjects WHERE SubjectType <> 8 AND ISNULL(IsActive,1) = 1");
            if (dt_1 != null)
            {
                ddlparentSubjects = dt_1.Rows.Cast <DataRow>().ToList().Select(x => new SelectListItem()
                {
                    Value = Convert.ToString(x["SubjectID"]), Text = Convert.ToString(x["SubjectName"])
                });
            }


            if (id != 0)
            {
                modelSubjects = getSubjectByID(id);
                foreach (var item in ddlSubjectType)
                {
                    if (item.Value == Convert.ToString(modelSubjects.SubjectType))
                    {
                        item.Selected = true;
                    }
                    slstSubjectTypeRet.Add(item);
                }


                foreach (var item in ddlparentSubjects)
                {
                    if (item.Value == Convert.ToString(modelSubjects.ParentSubjectID))
                    {
                        item.Selected = true;
                    }
                    slstParentSubjectRet.Add(item);
                }
            }

            ViewBag.MainModel             = modelSubjects;
            ViewBag.ddSubjectTypelist     = slstSubjectTypeRet;
            ViewBag.ddlparentSubjectslist = slstParentSubjectRet;
            return(View());
        }