public void EditTeacher(EditTeacherViewModel vm)
        {
            var teacher = vm.Teacher;

            context.Entry(teacher).State = System.Data.Entity.EntityState.Modified;
            Save();
        }
        //GET: EditTeacher
        public ActionResult EditTeacher(string id)
        {
            EditTeacherViewModel etvm = new EditTeacherViewModel();

            if (id != null)
            {
                UserStore <Models.Identity.ApplicationUser>   userStore   = new UserStore <Models.Identity.ApplicationUser>(context);
                UserManager <Models.Identity.ApplicationUser> userManager = new UserManager <Models.Identity.ApplicationUser>(userStore);

                var teacher = userManager.FindById(id);

                if (teacher == null)
                {
                    return(HttpNotFound());
                }

                etvm = new EditTeacherViewModel
                {
                    FirstName = teacher.FirstName,
                    LastName  = teacher.LastName,
                    Email     = teacher.Email,
                    Id        = id
                };
            }

            return(PartialView(etvm));
        }
 public ActionResult Edit([Bind(Include = "Teacher, Selected")] EditTeacherViewModel vm)
 {
     if (ModelState.IsValid)
     {
         repo.EditTeacher(vm);
         return(RedirectToAction("Index"));
     }
     return(View(vm));
 }
 public ActionResult Index(EditTeacherViewModel model)
 {
     if (ModelState.IsValid)
     {
         var user = db.Users.Find(User.Identity.GetUserId());
         if (user == null)
         {
             return(RedirectToAction("LogOff", "Account"));
         }
         user.Update(model);
         db.SaveChanges();
         SignInManager.SignIn(user, false, false);
         return(RedirectToAction("Index", new { message = ManageMessageId.UpdateUserInfoSuccess }));
     }
     return(View(model));
 }
        public EditTeacherViewModel GetEditTeacherViewModel(int id)
        {
            var teacher = GetTeacher(id);

            if (teacher == null)
            {
                return(null);
            }

            var vm = new EditTeacherViewModel
            {
                Teacher = teacher
            };

            return(vm);
        }
Exemple #6
0
        public ActionResult EditTeacher(string id, EditTeacherViewModel model)
        {
            // Redirect to edit student if it's not a teacher
            if (!UserManager.IsInRole(id, "Teacher"))
            {
                return(RedirectToAction(nameof(EditStudent), new { id }));
            }

            if (ModelState.IsValid)
            {
                var user = db.Users.Find(id);
                if (user == null)
                {
                    return(HttpNotFound());
                }
                user.Update(model);
                db.SaveChanges();
                HttpContext.GetOwinContext().Get <ApplicationSignInManager>().SignIn(user, false, false);
                return(RedirectToAction("Index"));
            }
            MakeBreadCrumbs();
            return(View(model));
        }
        public async Task <IActionResult> EditTeacherData(EditTeacherViewModel model)
        {
            if (ModelState.IsValid)
            {
                Teacher teacher = _teacherRepository.GetTeacherById(model.Id);
                if (teacher == null)
                {
                    ViewBag.ErrorMessage = $"The teacher with Id = { model.Id } could not be found";
                    return(View("NotFound"));
                }
                IdentityUser user = await userManager.FindByIdAsync(teacher.IdentityUserId);

                user.Email       = model.EmailAddress;
                user.PhoneNumber = model.PhoneNumber;
                IdentityResult result = await userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    // Update Teacher personal information
                    teacher.Firstname    = model.Firstname;
                    teacher.Middlename   = model.Middlename;
                    teacher.Lastname     = model.Lastname;
                    teacher.Gender       = model.Gender;
                    teacher.DateOfBirth  = model.DateOfBirth.ToString();
                    teacher.PhoneNumber  = model.PhoneNumber;
                    teacher.EmailAddress = model.EmailAddress;
                    teacher.Religion     = model.Religion;
                    if (model.Photo != null)
                    {
                        if (model.ExistingPhotoPath != null)
                        {
                            string filePath = Path.Combine(hostingEnvironment.WebRootPath, "uploads", model.ExistingPhotoPath);
                            System.IO.File.Delete(filePath);
                        }
                        teacher.ProfilePhotoPath = processFileUpload.UploadImage(model.Photo, "uploads");
                    }
                    _teacherRepository.UpdateTeacherData(teacher);


                    // Update Teacher contact information
                    TeacherContactInformation contactInformation = _teacherRepository.GetTeacherContactInfoById(teacher.Id);
                    contactInformation.Address1 = model.Address1;
                    contactInformation.Address2 = model.Address2;
                    contactInformation.AlternateEmailAddress = model.AlternateEmailAddress;
                    contactInformation.ZipCode             = model.ZipCode;
                    contactInformation.HomePhone           = model.HomePhone;
                    contactInformation.MobilePhone         = model.MobilePhone;
                    contactInformation.NextOfKinFirstname  = model.NextOfKinFirstname;
                    contactInformation.NextOfKinLastname   = model.NextOfKinLastname;
                    contactInformation.RelationToNextOfKin = model.RelationToNextOfKin;
                    contactInformation.PhoneOfNextOfKin    = model.PhoneOfNextOfKin;
                    contactInformation.EmailOfNextOfKin    = model.EmailOfNextOfKin;
                    contactInformation.CountryId           = model.CountryId;
                    _teacherRepository.UpdateTeacherContactData(contactInformation);


                    // Update Teacher highest degree information
                    TeacherHighestDegree highestDegree = _teacherRepository.GetTeacherHighestDegreeById(contactInformation.Id);
                    highestDegree.NameOfInstitution = model.NameOfInstitution;
                    highestDegree.YearEnrolled      = model.YearEnrolled.ToString();
                    highestDegree.YearOfGraduation  = model.YearOfGraduation.ToString();
                    highestDegree.DegreeAttained    = model.DegreeAttained;
                    highestDegree.CGPA = model.CGPA;
                    _teacherRepository.UpdateTeacherHighestDegreeData(highestDegree);

                    // Update teacher other degree information
                    TeacherOtherDegree otherDegree = _teacherRepository.GetTeacherOtherDegreeById(highestDegree.Id);
                    otherDegree.NameOfInstitution = model.OtherNameOfInstitution;
                    otherDegree.YearOfEnrollement = model.YearOfEnrollement.ToString();
                    otherDegree.YearOfGraduation  = model.OtherYearOfGraduation.ToString();
                    otherDegree.DegreeAttained    = model.OtherDegreeAttained;
                    otherDegree.CGPA = model.OtherCGPA;
                    _teacherRepository.UpdateTeacherOtherDegreeData(otherDegree);
                    return(RedirectToAction("allteachers"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> EditTeacherData(long Id)
        {
            Teacher teacher = _teacherRepository.GetTeacherById(Id);

            if (teacher == null)
            {
                ViewBag.ErrorMessage = $"The Teacher with Id = { Id } could not be found!";
                return(View("NotFound"));
            }
            IdentityUser user = await userManager.FindByIdAsync(teacher.IdentityUserId);

            TeacherContactInformation contactInformation = _teacherRepository.GetTeacherContactInfoById(teacher.Id);
            TeacherHighestDegree      highestDegree      = _teacherRepository.GetTeacherHighestDegreeById(contactInformation.Id);
            TeacherOtherDegree        otherDegree        = _teacherRepository.GetTeacherOtherDegreeById(highestDegree.Id);
            State state = stateRepository.GetRelatedCountry(contactInformation.CountryId);
            EditTeacherViewModel model = new EditTeacherViewModel
            {
                // Personal Information
                Id                = teacher.Id,
                IdentityUser      = user,
                Firstname         = teacher.Firstname,
                Middlename        = teacher.Middlename,
                Lastname          = teacher.Lastname,
                Gender            = teacher.Gender,
                DateOfBirth       = Convert.ToDateTime(teacher.DateOfBirth),
                PhoneNumber       = teacher.PhoneNumber,
                EmailAddress      = teacher.EmailAddress,
                ExistingPhotoPath = teacher.ProfilePhotoPath,

                //Contact Information
                Address1              = contactInformation.Address1,
                Address2              = contactInformation.Address2,
                CountryId             = contactInformation.CountryId,
                StateId               = state.Id,
                ZipCode               = contactInformation.ZipCode,
                HomePhone             = contactInformation.HomePhone,
                MobilePhone           = contactInformation.MobilePhone,
                AlternateEmailAddress = contactInformation.AlternateEmailAddress,

                // Next of Kin information
                NextOfKinFirstname  = contactInformation.NextOfKinFirstname,
                NextOfKinLastname   = contactInformation.NextOfKinLastname,
                RelationToNextOfKin = contactInformation.RelationToNextOfKin,
                PhoneOfNextOfKin    = contactInformation.PhoneOfNextOfKin,
                EmailOfNextOfKin    = contactInformation.EmailOfNextOfKin,

                // Accademic information
                // == Highest degree information == //
                NameOfInstitution = highestDegree.NameOfInstitution,
                YearEnrolled      = Convert.ToDateTime(highestDegree.YearEnrolled),
                YearOfGraduation  = Convert.ToDateTime(highestDegree.YearOfGraduation),
                CGPA           = highestDegree.CGPA,
                DegreeAttained = highestDegree.DegreeAttained,

                // == Other degree information == //
                OtherNameOfInstitution = otherDegree.NameOfInstitution,
                YearOfEnrollement      = Convert.ToDateTime(otherDegree.YearOfEnrollement),
                OtherYearOfGraduation  = Convert.ToDateTime(otherDegree.YearOfGraduation),
                OtherDegreeAttained    = otherDegree.DegreeAttained,
                OtherCGPA = otherDegree.CGPA
            };

            States(model);
            ListAllDepartments(model);
            return(View(model));
        }
        public ActionResult EditTeacher(EditTeacherViewModel edited)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("_TeacherListPartial"));
            }

            if (edited == null)
            {
                return(HttpNotFound());
            }

            //Add contents of arg to a new post in the database
            UserStore <Models.Identity.ApplicationUser>   userStore   = new UserStore <Models.Identity.ApplicationUser>(context);
            UserManager <Models.Identity.ApplicationUser> userManager = new UserManager <Models.Identity.ApplicationUser>(userStore);

            ApplicationUser teacher = userManager.FindById(edited.Id);

            if (teacher == null)
            {
                return(RedirectToAction("_TeacherListPartial"));
            }

            teacher.FirstName = edited.FirstName;
            teacher.LastName  = edited.LastName;
            teacher.Email     = edited.Email;
            teacher.UserName  = edited.Email;

            var result = userManager.Update(teacher);

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error);
                }

                return(RedirectToAction("_TeacherListPartial"));
            }

            // Want to change password?
            if (edited.Password != null)
            {
                if (edited.Password == edited.ConfirmPassword)
                {
                    //result = userManager.ChangePassword(teacher.Id, teacher.PasswordHash, edited.Password);

                    PasswordHasher ph = new PasswordHasher();

                    string hashed = ph.HashPassword(edited.Password);

                    var updatedUserPw = context.Users.Find(teacher.Id);

                    updatedUserPw.PasswordHash = hashed;

                    context.Entry(updatedUserPw).State = EntityState.Modified;
                }
            }

            context.SaveChanges();

            return(RedirectToAction("_TeacherListPartial"));
        }