public async Task <IActionResult> TeacherDetails(long Id) { Teacher teacher = _teacherRepository.GetTeacherById(Id); IdentityUser user = await userManager.FindByIdAsync(teacher.IdentityUserId); teacher.IdentityUser = user; if (teacher == null) { ViewBag.ErrorMessage = $"The Teacher with Id = { Id } could not be found."; return(View("NotFound")); } var contactInformation = _teacherRepository.GetTeacherContactInfoById(teacher.Id); var highestDegree = _teacherRepository.GetTeacherHighestDegreeById(contactInformation.Id); var otherDegree = _teacherRepository.GetTeacherOtherDegreeById(highestDegree.Id); Country country = countryRepository.GetCountryById(contactInformation.CountryId); State state = stateRepository.GetRelatedCountry(contactInformation.CountryId); contactInformation.Country = country; TeacherDetailsViewModel model = new TeacherDetailsViewModel { Teacher = teacher, TeacherContactInformation = contactInformation, TeacherHighestDegree = highestDegree, TeacherOtherDegree = otherDegree, State = state.StateName }; return(View(model)); }
public async Task <IActionResult> EditTeacher(string id) { var teacher = await this.userService.GetTeacherAsync(id); TeacherDetailsViewModel model = this.mapper.Map <TeacherDetailsViewModel>(teacher); return(this.View(model)); }
public TeacherDetailsViewModel FindById(int teacherId) { var teacher = this.db.Teachers .Include(t => t.ApplicationUser) .FirstOrDefault(x => x.Id == teacherId); var levelsIds = this.db.LevelTeachers.Where(x => x.TeacherId == teacherId).Select(x => x.LevelId).ToArray(); var levels = this.db.Levels.Where(x => levelsIds.Contains(x.Id)); var groups = this.db.Groups.Where(g => g.TeacherId == teacher.Id).Select(g => new GroupSelectionViewModel { Id = g.Id, Name = g.Name, }).ToList(); string dissmissalDate = teacher.DismissalDate == null ? InfoStrings.GeneralNotSpecified : teacher.DismissalDate.Value.ToString(Constants.dateOnlyFormat); string phoneNumber = InfoStrings.GeneralNotSpecified; string email = InfoStrings.GeneralNotSpecified; string username = InfoStrings.GeneralNotSpecified; if (string.IsNullOrEmpty(teacher.ApplicationUserId) == false) { phoneNumber = teacher.ApplicationUser.PhoneNumber; email = teacher.ApplicationUser.Email; username = teacher.ApplicationUser.UserName; } var model = new TeacherDetailsViewModel { Id = teacher.Id, FirstName = teacher.FirstName, LastName = teacher.LastName, Gender = teacher.Gender, Salary = string.Format(teacher.Salary.ToString(), Constants.salaryFormat), HiringDate = teacher.HiringDate.ToString(Constants.dateOnlyFormat), DismissalDate = dissmissalDate, QualifiedLevels = levels, Status = teacher.Status, ProfilePicURI = teacher.ProfilePicURI, Groups = groups, Username = username, Email = email, PhoneNumber = phoneNumber }; return(model); }
public async Task <IActionResult> EditTeacher(TeacherDetailsViewModel model) { if (this.ModelState.IsValid) { var teacher = await this.userService.GetTeacherAsync(model.Id); this.mapper.Map(model, teacher, typeof(TeacherDetailsViewModel), typeof(Teacher)); await this.userService.SaveChangesAsync(); this.TempData["SuccessMsg"] = "Промяната е записана успешно"; return(this.Redirect("/Home/Success")); } return(this.View(model)); }
public IActionResult TeacherDetailsView(int id) { var viewModel = new TeacherDetailsViewModel(_teacherRepository.GetDetailsDtoById(id)); return(View(viewModel)); }