public ActionResult Edit(int id)
        {
            if (Session["UserName"] != null)
            {
                var instructor = _context.Instructors.SingleOrDefault(c => c.id == id);
                if (instructor == null)
                {
                    return(HttpNotFound());
                }
                Instructor ins = new Instructor();
                ins.id         = instructor.id;
                ins.username   = instructor.username;
                ins.password   = instructor.password;
                ins.name       = instructor.name;
                ins.section    = instructor.section;
                ins.subject    = instructor.subject;
                ins.image_path = instructor.image_path;
                var viewmodel = ShowAllInstructor();
                //var data = new InstructorViewModel
                //{
                //    Inst_list = viewmodel.Inst_list,
                //    Instructors = ins

                //};
                var data = new InstructorEditModel
                {
                    id         = ins.id,
                    username   = ins.username,
                    name       = ins.name,
                    password   = ins.password,
                    section    = ins.section,
                    subject    = ins.subject,
                    image_path = ins.image_path
                };


                return(View(data));
            }
            else
            {
                var data = new User()
                {
                    userType = "Invalid Login"
                };
                return(RedirectToAction("Index", "Home", data));
            }
        }
        public ActionResult EditInstructor(InstructorEditModel instructor)
        {
            var data1 = ShowAllInstructor();

            data1.extra = "Invalid State";
            if (!ModelState.IsValid)
            {
                //var errors = ModelState.Values.All(modelState => modelState.Errors.Count == 0);

                return(RedirectToAction("Index", data1));
            }

            var data = ShowAllInstructor();

            data.extra = "Instructor Not Edited!";
            //Encrypted Passwod
            SHA256 mySHA256 = SHA256Managed.Create();

            byte[] hashvalue;
            byte[] byteArray = Encoding.ASCII.GetBytes((string)instructor.password);
            hashvalue           = mySHA256.ComputeHash(byteArray);
            instructor.password = Encoding.ASCII.GetString(hashvalue);

            byte[] hashvalue1;
            byte[] byteArray1 = Encoding.ASCII.GetBytes((string)instructor.repassword);
            hashvalue1            = mySHA256.ComputeHash(byteArray1);
            instructor.repassword = Encoding.ASCII.GetString(hashvalue1);

            if (instructor.password == instructor.repassword)
            {
                var instructorInDb = _context.Instructors.Single(c => c.id == instructor.id);
                instructorInDb.username = instructor.username;
                instructorInDb.name     = instructor.name;
                instructorInDb.section  = instructor.section;
                instructorInDb.subject  = instructor.subject;
                instructorInDb.password = instructor.password;

                //Before Image

                HttpPostedFileBase photo = Request.Files["image"];
                string             destinationDirectory =
                    @"C:\Users\Mujeeb Arshad\Documents\Visual Studio 2013\Projects\Attendance\Attendance\Content\assets\img\";
                string destinationDirectory1 = destinationDirectory + photo.FileName;
                if (photo.FileName != null && photo.FileName != "")
                {
                    photo.SaveAs(destinationDirectory1);
                    if (System.IO.File.Exists(destinationDirectory + instructor.username + ".jpg"))
                    {
                        System.IO.File.Delete(destinationDirectory + instructor.username + ".jpg");
                    }

                    System.IO.File.Move(destinationDirectory1,
                                        destinationDirectory + instructor.username + ".jpg");
                }
                instructor.image_path = "../../Content/assets/img/" + instructor.username + ".jpg";


                //After Image
                instructorInDb.image_path = instructor.image_path;

                _context.SaveChanges();



                data       = ShowAllInstructor();
                data.extra = "Instructor has been Edited!";
            }
            return(RedirectToAction("Index", data));
        }