public ActionResult updateStudent(edu_course.Models.Student stu, int id)
        {
            try
            {
                int           schoolid          = Convert.ToInt32(Session["school"]);
                ClassDBHandle gc                = new ClassDBHandle();
                List <tbl_ClassValidation> list = gc.GetClass(schoolid);
                ViewBag.schoolclass = new SelectList(list, "Class_Id", "Name");
                SectionDBHandle section = new SectionDBHandle();
                List <tbl_SectionValidation> sectionlist = section.GetSection(schoolid);
                ViewBag.schoolsection = new SelectList(sectionlist, "SectionID", "SectionName");


                var data = db.Students.Where(x => x.Id == id).First();

                if (data != null)
                {
                    data.Name       = stu.Name;
                    data.ContactNo  = stu.ContactNo;
                    data.Email      = stu.Email;
                    data.Address    = stu.Address;
                    data.Class_Id   = data.Class_Id;
                    data.Section_Id = data.Section_Id;

                    db.Entry(data).State = EntityState.Modified;
                    db.SaveChanges();
                    ViewBag.Message = "Data Successfully Updated";
                    ModelState.Clear();
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Not Submitted";
                return(View());
            }
            return(RedirectToAction("viewstudent", "Home"));
        }
        public ActionResult addstudent(edu_course.Models.tbl_StudentValidation s)
        {
            try
            {
                int           schoolid = Convert.ToInt32(Session["school"]);
                ClassDBHandle gc       = new ClassDBHandle();

                List <tbl_ClassValidation> list = gc.GetClass(schoolid);
                ViewBag.schoolclass = new SelectList(list, "Class_Id", "Name");
                SectionDBHandle section = new SectionDBHandle();
                List <tbl_SectionValidation> sectionlist = section.GetSection(schoolid);
                ViewBag.schoolsection = new SelectList(sectionlist, "SectionID", "SectionName");


                edu_course.Models.Student a = new edu_course.Models.Student();
                var userWithSameEmail       = db.Students.Where(m => m.Email == s.Email).SingleOrDefault(); //checking if the emailid already exits for any user
                if (userWithSameEmail == null)
                {
                    s.RegNo = StudentRegNo(s, s.Name);

                    string filename  = Path.GetFileNameWithoutExtension(s.UserImageFIle.FileName);
                    string extension = Path.GetExtension(s.UserImageFIle.FileName);
                    filename = DateTime.Now.ToString("yymmssff") + extension;

                    a.ImagePath = "~/Content/img/users/" + filename;
                    //image ko folder me save krwanay ke leye
                    filename = Path.Combine(Server.MapPath("~/Content/img/users/"), filename);
                    s.UserImageFIle.SaveAs(filename);
                    a.Class_Id   = s.Class_Id;
                    a.Section_Id = s.Section_Id;
                    a.School_Id  = Convert.ToInt32(Session["school"]);
                    a.Name       = s.Name;
                    a.RegNo      = s.RegNo;
                    a.Address    = s.Address;
                    a.Email      = s.Email;
                    a.ContactNo  = s.ContactNo;
                    a.Password   = s.Password;

                    a.RegisterationDate = DateTime.Now;

                    db.Students.Add(a);
                    db.SaveChanges();
                }

                else
                {
                    ViewBag.Message = "User with this Email Already Exist";
                    return(View());
                }

                int        studentlatestid = a.Id;
                loginTable l = new loginTable();
                l.UserId   = studentlatestid;
                l.Name     = a.Name;
                l.Password = a.Password;
                l.RoleID   = 4;
                l.Email    = a.Email;
                db.loginTables.Add(l);
                db.SaveChanges();
                ModelState.Clear();
                ViewBag.Message = "Data Submitted";
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Not Submitted";
                return(View());
            }
            return(View());
        }