public ActionResult Edit(StudentEditViewModel userprofile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userprofile.Student).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(userprofile);
 }
        public ActionResult Create(StudentEditViewModel userprofile)
        {
            if (ModelState.IsValid)
            {
                var student = userprofile.Student;
                student.CreationDate = DateTime.Now;
                //Todo: currently requires two trips to db to autogenerate username.
                db.UserProfiles.Add(student);
                db.SaveChanges();
                student.UserName = "******" + student.UserId;
                student.CreationDate = DateTime.Now;
                db.Entry(student).State = EntityState.Modified;

                var photo = this.Session["Photo"] as byte[];
                if (photo != null)
                {
                    userprofile.Student.Photo = photo;
                }

                db.SaveChanges();
                Roles.AddUserToRole(userprofile.Student.UserName, Helpers.STUDENT_ROLE);
                this.Session["Photo"] = null;
                return RedirectToAction("Index");
            }

            return View(userprofile);
        }
        //
        // GET: /Student/Edit/5
        public ActionResult Edit(int id = 0)
        {
            StudentEditViewModel vm = new StudentEditViewModel();

            vm.Student = db.UserProfiles.Find(id);
            if (vm.Student == null)
            {
                return HttpNotFound();
            }
            var levels = from Level d in Enum.GetValues(typeof(Level))
                             select new { Name = Enum.GetName(typeof(Level), d), Value = Enum.GetName(typeof(Level),d) };

            Level currentLevel = vm.Student.StudentLevel;
            vm.LevelsList = new SelectList(levels, "Name", "Value", currentLevel);
            vm.StudentLevel = currentLevel;
            return View(vm);
        }
        //
        // GET: /Student/Create
        public ActionResult Create()
        {
            StudentEditViewModel vm = new StudentEditViewModel();

              var levels = from Level d in Enum.GetValues(typeof(Level))
                             select new { Name = Enum.GetName(typeof(Level), d), Value = Enum.GetName(typeof(Level),d) };

              vm.LevelsList = new SelectList(levels, "Name", "Value");

              vm.Student = new UserProfile();

              return View(vm);
        }