public ActionResult Edit(StudentEditModel model) { try { Domain.Core.Student student = _studentRepository.Get(User.Identity.Name); if (student != null) { student.FirstName = model.FirstName; student.MiddleName = model.MiddleName; student.Group = model.Group; student.YearOfStudy = model.YearOfStudy; student.BirthDate = model.BirthDate; student.Email = model.Email; student.LastName = model.LastName; student.PhoneNumber = model.PhoneNumber; _studentRepository.Update(student); return(RedirectToAction("Index")); } ModelState.AddModelError("", @"User isn`t found"); } catch (Exception ex) { ModelState.AddModelError("", @"Something went wrong"); _logger.Error(ex, "Edit (POST) method of controller Student: Error edit a user.", ex); } return(View(model)); }
public ActionResult StudentEdit(int id) { var model = new StudentEditModel(); model = ProfileManageRepo.editStudentProfile(id); return(View(model)); }
public StudentEditModel editStudentProfile(int userID) { var result = new StudentEditModel(); try { //var objToSave = DbContext.UserInfos.FirstOrDefault(u => (u.Email == emailOrUserName || u.UserName == emailOrUserName) && u.Password == password); var userInfo = DbContext.UserInfos.FirstOrDefault(u => u.ID == userID); var student = DbContext.Students.FirstOrDefault(s => s.S_ID == userID); result.Email = userInfo.Email; result.Name = userInfo.Name; result.UserName = userInfo.UserName; if (student == null) { result.Class = ""; result.DOB = ""; result.Location = ""; } else { result.Class = student.Class; result.DOB = student.DOB.ToString("dd-MM-yyyy"); result.Location = student.location; } } catch (Exception ex) { result = null; } return(result); }
public ActionResult Edit() { try { Domain.Core.Student student = _studentRepository.Get(User.Identity.Name); if (student != null) { StudentEditModel model = new StudentEditModel { FirstName = student.FirstName, LastName = student.LastName, MiddleName = student.MiddleName, BirthDate = student.BirthDate, PhoneNumber = student.PhoneNumber, Group = student.Group, YearOfStudy = student.YearOfStudy, Email = student.Email }; return(View(model)); } _logger.Warn("Get_Method of Student Controller user=null. User recive httpnotfound."); return(HttpNotFound()); } catch (Exception ex) { _logger.Error(ex, "Student Redirect to LoginPage"); return(HttpNotFound()); } }
private async void BindStudentInfo() { string strErrorMsg = string.Empty; try { if (studentId != 0) { //选择了修改模式 studentEditModel = await studentAsyncProxy.CallAsync(c => c.GetStudentById(this.studentId)); txtName.Text = studentEditModel.Name; txtNickName.Text = studentEditModel.Nickname; dateBirth.Text = studentEditModel.Birthdate.ToString("MM/dd/yyyy"); txtEmail.Text = studentEditModel.Email; txtMomsName.Text = studentEditModel.Momsname; txtMomsPhone.Text = studentEditModel.Momsphone; txtDadsName.Text = studentEditModel.Dadsname; txtDadsPhone.Text = studentEditModel.Dadsphone; txtAddress.Text = studentEditModel.Address; txtSchool.Text = studentEditModel.School; txtGrade.Text = studentEditModel.Grade; txtOriginalClass.Text = studentEditModel.OriginalClass; txtRelationShip.Text = studentEditModel.RelationShip; cmbConsultant.Text = studentEditModel.ConsultantName; cmbStatus.Text = studentEditModel.StatusText; numConsRate.Value = Convert.ToDouble(studentEditModel.ConsultantRate); foreach (string classpath in studentEditModel.ClassPath) { RadTreeViewItem targetItem = this.ClassTypeTree.GetItemByPath(classpath, "|"); targetItem.IsChecked = true; } } } catch (TimeoutException timeProblem) { strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message; } catch (FaultException <LCFault> af) { strErrorMsg = af.Detail.Message; } catch (FaultException unknownFault) { strErrorMsg = UIResources.UnKnowFault + unknownFault.Message; } catch (CommunicationException commProblem) { strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace; } catch (Exception ex) { strErrorMsg = ex.Message; } if (strErrorMsg != string.Empty) { await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "绑定学员信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null); } }
/// <summary> /// 根据学员id获取编辑对象 /// </summary> /// <param name="id"></param> /// <returns></returns> public StudentEditModel GetStudentById(int id) { try { StudentEditModel studentEditModel = new StudentEditModel(); Repository <student> studentDal = _unitOfWork.GetRepository <student>(); student studentEntity = studentDal.GetObjectByKey(id).Entity; if (studentEntity != null) { studentEditModel.InitEditModel(studentEntity); } return(studentEditModel); } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } }
public async Task <bool> UpdateStudentAsync(int id, StudentEditModel studentForUpdate) { var student = await _studentRepository.GetByIdAsync(id); student = _mapper.Map <StudentEditModel, Student>(studentForUpdate, student); return(await _studentRepository.UpdateAsync(student)); }
public async Task <IActionResult> UpdateStudent(int id, [FromBody] StudentEditModel studentForUpdate) { var student = await _quantumITAppService.UpdateStudentAsync(id, studentForUpdate); return(Ok(student)); throw new Exception($"updating student {id} failed on save!"); }
public async Task <IActionResult> UpdateStudent(int id, [FromBody] StudentEditModel studentForUpdate) { var student = await _quantumITAppService.UpdateStudentAsync(id, studentForUpdate); if (!student) { return(BadRequest(_error)); } return(Ok(student)); }
public IActionResult Edit(StudentEditModel model) { if (ModelState.IsValid) { var studentEdited = studentRepository.Edit(model); if (studentEdited != null) { return(RedirectToAction("detail", "Home", new { id = model.ID })); } } return(View(model)); }
public IActionResult Edit(int id) { var student = studentRepository.Get(id); var editStudent = new StudentEditModel() { ID = student.ID, Classes = student.Classes, DoB = student.DoB, Email = student.Email, Fullname = student.Fullname }; return(View(editStudent)); }
public async Task <bool> ValidStudentEdit(int id, StudentEditModel studentToUpdate) { var students = await _studentRepository.GetStudentsBySubjectIdAsync(studentToUpdate.SubjectId); var studentsToCheck = students.SkipWhile(st => st.Id == id); var studentFound = studentsToCheck.FirstOrDefault(st => st.SurName.ToLower().Trim() == studentToUpdate.SurName.ToLower().Trim()); if (studentFound == null) { return(true); } return(false); }
public ActionResult DetailsEdit(StudentEditModel modelStudent) { var myStudent = _studentRepository.GetById(modelStudent.Id); modelStudent.Tutor1 = _parentRepository.GetById(modelStudent.Tutor1.Id); modelStudent.Tutor2 = _parentRepository.GetById(modelStudent.Tutor2.Id); var studentModel = Mapper.Map <StudentEditModel, Student>(modelStudent); _studentRepository.UpdateStudentFromStudentEditModel(studentModel, myStudent); const string title = "Estudiante Actualizado"; var content = "El estudiante " + myStudent.FullName + " ha sido actualizado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.InformationMessage); return(RedirectToAction("Details/" + modelStudent.Id)); }
public async Task <bool> UpdateStudentAsync(int id, StudentEditModel studentForUpdate) { //var student = await _studentRepository.GetByIdAsync(id); var subjectId = studentForUpdate.SubjectId; if (await ValidStudentEdit(id, studentForUpdate)) { var student = _mapper.Map <Student>(studentForUpdate); return(await _studentRepository.UpdateAsync(id, student)); } return(false); }
public ActionResult StudentEdit(StudentEditModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = ProfileManageRepo.saveStudentProfile(model, HttpUtil.UserProfile.ID); if (result.HasError) { ViewBag.Error = result.Message; return(View(model)); } return(View(model)); }
public Student Edit(StudentEditModel model) { var student = Get(model.ID); if (student != null) { student.Classes = model.Classes; student.Fullname = model.Fullname; student.DoB = model.DoB; student.Aavatar = @"noavatar.png"; student.Email = model.Email; return(student); } return(null); }
public IActionResult Edit(StudentEditModel model) { if (ModelState.IsValid) { var student = db.Students.SingleOrDefault(s => s.ID == model.ID); student.FirstMidName = model.FirstMidName; student.LastName = model.LastName; student.EnrollmentDate = model.EnrollmentDate.GetValueOrDefault(); db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public StudentViewModel SaveStudentEditModelToDb(StudentEditModel studentEditModel) { Student _studentDbModel; if (studentEditModel.StudentId != 0) { _studentDbModel = _dataManager.Students.GetStudentById(studentEditModel.StudentId); } else { _studentDbModel = new Student(); } _studentDbModel.StudentName = studentEditModel.StudentName; _dataManager.Students.SaveStudent(_studentDbModel); return(StudentDBToViewModelById(_studentDbModel.StudentId)); }
private async void BaseWindow_Loaded(object sender, RoutedEventArgs e) { string strErrorMsg = string.Empty; try { studentAsyncProxy = await Task.Run(() => ServiceHelper.GetStudentService()); currentStudent = await studentAsyncProxy.CallAsync(c => c.GetStudentById(this.StudentId)); NameLable.Content = currentStudent.Name; NickNameLable.Content = currentStudent.Nickname; RemainBalanceLable.Content = currentStudent.RemainingBalance.ToString(); NumRecharge.Value = currentStudent.NeedRecharge; } catch (TimeoutException timeProblem) { strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message; } catch (FaultException <LCFault> af) { strErrorMsg = af.Detail.Message; } catch (FaultException unknownFault) { strErrorMsg = UIResources.UnKnowFault + unknownFault.Message; } catch (CommunicationException commProblem) { strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace; } catch (Exception ex) { strErrorMsg = ex.Message; } if (strErrorMsg != string.Empty) { await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "初始化界面失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null); return; } }
public StudentEditModel GetStudentEditModel(int studentid = 0) { if (studentid != 0) { var _dirDB = _dataManager.Students.GetStudentById(studentid); var _dirEditModel = new StudentEditModel() { StudentId = _dirDB.StudentId, StudentName = _dirDB.StudentName }; return(_dirEditModel); } else { return(new StudentEditModel() { }); } }
public IActionResult DeleteStudent(StudentEditModel model) { if (ModelState.IsValid) { _studentData.Delete(model.StudentName); foreach (var behavior in _behaviorData.GetAll()) { if (behavior.StudentName == model.StudentName) { _behaviorData.Delete(behavior.BehaviorName, model.StudentName); } } return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public Student UpdateStudentFromStudentEditModel(StudentEditModel studentEditModel, Student student) { student.FirstName = studentEditModel.FirstName; student.LastName = studentEditModel.LastName; student.FullName = (studentEditModel.FirstName + " " + studentEditModel.LastName).Trim(); student.Country = studentEditModel.Country; student.IdNumber = studentEditModel.IdNumber; student.BirthDate = studentEditModel.BirthDate; student.Gender = Utilities.IsMasculino(studentEditModel.Gender); student.Nationality = studentEditModel.Nationality; student.State = studentEditModel.State; student.City = studentEditModel.City; student.Address = studentEditModel.Address; student.Biography = studentEditModel.Biography; student.StartDate = studentEditModel.StartDate; student.BloodType = studentEditModel.BloodType; student.AccountNumber = studentEditModel.AccountNumber; student.Tutor1 = studentEditModel.FirstParent; student.Tutor2 = studentEditModel.SecondParent; return(Update(student)); }
/// <summary> /// 删除学员信息 /// </summary> /// <param name="deleteUserModel">删除学员信息</param> public bool Delete(StudentEditModel deleteStudentEditModel) { try { return(DeleteById(deleteStudentEditModel.Id)); } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } }
public IActionResult AddStudent(StudentEditModel model) { if (ModelState.IsValid) { var newStudent = new Student(); newStudent.StudentName = model.StudentName; if (_studentData.GetAll().Count() > 0) { newStudent.Id = _studentData.GetAll().Max(m => m.Id) + 1; } else { newStudent.Id = 1; } newStudent = _studentData.Add(newStudent); return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public Result <UserInfo> saveStudentProfile(StudentEditModel model, int id) { var result = new Result <UserInfo>(); try { if (DbContext.UserInfos.Any(u => u.UserName == model.UserName && u.ID != id)) { result.HasError = true; result.Message = "Username Exists"; return(result); } if (DbContext.UserInfos.Any(u => u.Email == model.Email && u.ID != id)) { result.HasError = true; result.Message = "Email Exists"; return(result); } var objToSaveUserInfo = DbContext.UserInfos.FirstOrDefault(u => u.ID == id); var studentObj = DbContext.Students.FirstOrDefault(u => u.S_ID == id); objToSaveUserInfo.UserName = model.UserName; objToSaveUserInfo.Name = model.Name; objToSaveUserInfo.Email = model.Email; if (!string.IsNullOrEmpty(model.OldPassword) || !string.IsNullOrWhiteSpace(model.OldPassword)) { if (!string.IsNullOrEmpty(model.NewPassword) || !string.IsNullOrWhiteSpace(model.NewPassword)) { if (!string.IsNullOrEmpty(model.ConfirmPassword) || !string.IsNullOrWhiteSpace(model.ConfirmPassword)) { if (objToSaveUserInfo.Password == model.OldPassword) { if (model.NewPassword == model.ConfirmPassword) { objToSaveUserInfo.Password = model.NewPassword; } else { result.HasError = true; result.Message = "New password and confirm password are not matched"; return(result); } } else { result.HasError = true; result.Message = "Old password is not matched"; return(result); } } else { result.HasError = true; result.Message = "Confirm Password field can not remain empty"; return(result); } } else { result.HasError = true; result.Message = "New password field can not remain empty"; return(result); } } else if (!string.IsNullOrEmpty(model.NewPassword) || !string.IsNullOrWhiteSpace(model.NewPassword)) { result.HasError = true; result.Message = "You must need to fill the old password first"; return(result); } else if (!string.IsNullOrEmpty(model.ConfirmPassword) || !string.IsNullOrWhiteSpace(model.ConfirmPassword)) { result.HasError = true; result.Message = "You need to fill the perious fields first"; return(result); } try { if (!string.IsNullOrEmpty(model.DOB) || !string.IsNullOrWhiteSpace(model.DOB)) { string sDOB = model.DOB; if (sDOB.Contains("-")) { var strings = sDOB.Split('-'); if (strings.Count() == 3) { try { if ((Int32.Parse(strings[0]) > 0 && Int32.Parse(strings[0]) <= 31) && (Int32.Parse(strings[1]) > 0 && Int32.Parse(strings[1]) <= 12) && (Int32.Parse(strings[2]) > 1900 && Int32.Parse(strings[2]) <= Int32.Parse(DateTime.Now.Year.ToString()))) { studentObj.DOB = DateTime.Parse(model.DOB); } } catch (Exception ex) { result.HasError = true; result.Message = "DOB is not in correct format"; return(result); } } else { result.HasError = true; result.Message = "DOB is not in correct format"; return(result); } } else { result.HasError = true; result.Message = "DOB is not in correct format"; return(result); } } } catch (Exception ex) { } try { studentObj.Class = model.Class; } catch (Exception ex) { studentObj.Class = ""; } try { studentObj.location = model.Location; } catch (Exception ex) { studentObj.location = ""; } DbContext.SaveChanges(); result.Data = objToSaveUserInfo; } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; return(result); } return(result); }
/// <summary> /// 更新学员信息 /// </summary> /// <param name="newClassEditModel">需要更新的学员信息</param> public StudentEditModel Update(StudentEditModel newStudentEditModel) { try { Repository <student> studentModuleDal = _unitOfWork.GetRepository <student>(); student studententity = studentModuleDal.GetObjectByKey(newStudentEditModel.Id).Entity; if (studententity != null) { studententity.address = newStudentEditModel.Address; studententity.center_id = newStudentEditModel.CenterId; studententity.dads_name = newStudentEditModel.Dadsname; studententity.dads_phone = newStudentEditModel.Dadsphone; studententity.email = newStudentEditModel.Email; studententity.extra_info = newStudentEditModel.ExtraInfo; studententity.google_contacts_id = newStudentEditModel.GoogleContactsId; studententity.grade = newStudentEditModel.Grade; studententity.moms_name = newStudentEditModel.Momsname; studententity.moms_phone = newStudentEditModel.Momsphone; studententity.original_class = newStudentEditModel.OriginalClass; studententity.relationship = newStudentEditModel.RelationShip; studententity.remaining_balance = newStudentEditModel.RemainingBalance; studententity.rfid_tag = newStudentEditModel.RfidTag; studententity.school = newStudentEditModel.School; studententity.students_birthdate = newStudentEditModel.Birthdate; studententity.students_name = newStudentEditModel.Name; studententity.students_nickname = newStudentEditModel.Nickname; studententity.student_id = newStudentEditModel.Id; studententity.status = newStudentEditModel.StatusId; if (studententity.consultants.Count > 0) { studententity.consultants.Clear(); } if (newStudentEditModel.ConsultantId != 0) { Repository <consultant> consultantModuleDal = _unitOfWork.GetRepository <consultant>(); consultant consultantEntity = consultantModuleDal.GetObjectByKey(newStudentEditModel.ConsultantId).Entity; studententity.consultants.Add(consultantEntity); } if (newStudentEditModel.ConsultantRate != 0) { studententity.consultant_check_rate = newStudentEditModel.ConsultantRate; } studententity.classess.Clear(); if (newStudentEditModel.ClassesId != null) { Repository <classes> classesDal = _unitOfWork.GetRepository <classes>(); foreach (int classid in newStudentEditModel.ClassesId) { classes cls = classesDal.GetObjectByKey(classid).Entity; studententity.classess.Add(cls); } } } _unitOfWork.AddAction(studententity, DataActions.Update); _unitOfWork.Save(); return(newStudentEditModel); } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } }
public ActionResult Edit(StudentEditModel modelStudent) { var validImageTypes = new [] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (modelStudent.FilePicture != null && modelStudent.FilePicture.ContentLength > 0) { if (!validImageTypes.Contains(modelStudent.FilePicture.ContentType)) { ModelState.AddModelError("FilePicture", "Por favor seleccione entre una imagen GIF, JPG o PNG"); } } if (ModelState.IsValid) { if ( _studentRepository.Filter(x => (x.IdNumber.Equals(modelStudent.IdNumber) || x.AccountNumber.Equals(modelStudent.AccountNumber)) && x.Id != modelStudent.Id) .Any()) { const string title = "Error!"; const string content = "Ya existe un estudiante con ese número de identidad o de cuenta."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.ErrorMessage); return(RedirectToAction("Index")); } try { if (modelStudent.FilePicture != null) { using (var binaryReader = new BinaryReader(modelStudent.FilePicture.InputStream)) { modelStudent.Photo = binaryReader.ReadBytes(modelStudent.FilePicture.ContentLength); } } var myStudent = _studentRepository.GetById(modelStudent.Id); Mapper.Map(modelStudent, myStudent); _studentRepository.Update(myStudent); const string title = "Estudiante Actualizado"; var content = "El estudiante " + myStudent.FullName + " ha sido actualizado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage); return(RedirectToAction("Index")); } catch { ViewBag.Tutor1Id = new SelectList(_tutorRepository.Query(x => x).OrderBy(x => x.FullName), "Id", "FullName", modelStudent.Tutor1); var items = ((Gender[])Enum.GetValues(typeof(Gender))).Select(c => new SelectListItem { Text = c.GetEnumDescription(), Value = c.ToString("D") }).ToList(); ViewBag.Genders = new List <SelectListItem>(items); ViewBag.Years = DateTimeController.GetYears(); ViewBag.Months = DateTimeController.GetMonths(); ViewBag.Days = DateTimeController.GetDaysForMonthAndYearStatic(1, DateTime.UtcNow.Year); return(View(modelStudent)); } } ViewBag.Tutor1Id = new SelectList(_tutorRepository.Query(x => x).OrderBy(x => x.FullName), "Id", "FullName", modelStudent.Tutor1); var items2 = ((Gender[])Enum.GetValues(typeof(Gender))).Select(c => new SelectListItem { Text = c.GetEnumDescription(), Value = c.ToString("D") }).ToList(); ViewBag.Genders = new List <SelectListItem>(items2); ViewBag.Years = DateTimeController.GetYears(); ViewBag.Months = DateTimeController.GetMonths(); ViewBag.Days = DateTimeController.GetDaysForMonthAndYearStatic(1, DateTime.UtcNow.Year); return(View(modelStudent)); }
private async void btnOK_Click(object sender, RoutedEventArgs e) { string name = ClassTypeTree.Name; if (cmbConsultant.SelectedItem == null) { this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "请选择该学员会籍顾问!"); return; } if (cmbStatus.SelectedItem == null) { this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "请选择该学员状态!"); return; } #region 新增 if (Om == OperationMode.AddMode) { string strErrorMsg = string.Empty; try { StudentEditModel newStudentModel = new StudentEditModel(); newStudentModel.Name = txtName.Text.Trim(); newStudentModel.Address = txtAddress.Text.Trim(); newStudentModel.Birthdate = dateBirth.DisplayDate; newStudentModel.ConsultantId = (cmbConsultant.SelectedItem as ConsultantModel).Id; newStudentModel.Dadsname = txtDadsName.Text.Trim(); newStudentModel.Dadsphone = txtDadsPhone.Text.Trim(); newStudentModel.Email = txtEmail.Text.Trim(); newStudentModel.Grade = txtGrade.Text.Trim(); newStudentModel.Momsname = txtMomsName.Text.Trim(); newStudentModel.Momsphone = txtMomsPhone.Text.Trim(); newStudentModel.Nickname = txtNickName.Text.Trim(); newStudentModel.OriginalClass = txtOriginalClass.Text.Trim(); newStudentModel.RelationShip = txtRelationShip.Text.Trim(); newStudentModel.School = txtSchool.Text.Trim(); newStudentModel.StatusId = (cmbStatus.SelectedItem as StatusModel).Id; newStudentModel.ClassesId = new List <int>(); newStudentModel.ConsultantRate = Convert.ToDecimal(numConsRate.Value); foreach (ClassDisplayModel cdm in ClassTypeTree.SelectedItems) { newStudentModel.ClassesId.Add(cdm.Id); } newStudentModel = await studentAsyncProxy.CallAsync(c => c.Add(newStudentModel)); this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "新增学员成功!"); this.DialogResult = true; } catch (TimeoutException timeProblem) { strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message; } catch (FaultException <LCFault> af) { strErrorMsg = af.Detail.Message; } catch (FaultException unknownFault) { strErrorMsg = UIResources.UnKnowFault + unknownFault.Message; } catch (CommunicationException commProblem) { strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace; } if (strErrorMsg != string.Empty) { await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "新增学员失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null); } } #endregion #region 修改 else { string strErrorMsg = string.Empty; try { studentEditModel.Address = txtAddress.Text.Trim(); studentEditModel.Birthdate = dateBirth.DisplayDate; studentEditModel.ConsultantId = (cmbConsultant.SelectedItem as ConsultantModel).Id; studentEditModel.Dadsname = txtDadsName.Text.Trim(); studentEditModel.Dadsphone = txtDadsPhone.Text.Trim(); studentEditModel.Email = txtEmail.Text.Trim(); studentEditModel.Grade = txtGrade.Text.Trim(); studentEditModel.Momsname = txtMomsName.Text.Trim(); studentEditModel.Momsphone = txtMomsPhone.Text.Trim(); studentEditModel.Nickname = txtNickName.Text.Trim(); studentEditModel.OriginalClass = txtOriginalClass.Text.Trim(); studentEditModel.RelationShip = txtRelationShip.Text.Trim(); studentEditModel.School = txtSchool.Text.Trim(); studentEditModel.StatusId = (cmbStatus.SelectedItem as StatusModel).Id; studentEditModel.Name = txtName.Text.Trim(); studentEditModel.ConsultantRate = Convert.ToDecimal(numConsRate.Value); studentEditModel.ClassesId = new List <int>(); foreach (ClassDisplayModel cdm in ClassTypeTree.SelectedItems) { studentEditModel.ClassesId.Add(cdm.Id); } studentEditModel = await studentAsyncProxy.CallAsync(c => c.Update(studentEditModel)); this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "修改学员成功!"); this.DialogResult = true; } catch (TimeoutException timeProblem) { strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message; } catch (FaultException <LCFault> af) { strErrorMsg = af.Detail.Message; } catch (FaultException unknownFault) { strErrorMsg = UIResources.UnKnowFault + unknownFault.Message; } catch (CommunicationException commProblem) { strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace; } if (strErrorMsg != string.Empty) { await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "修改学员失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null); } } #endregion }
public IActionResult SaveStudent(StudentEditModel model) { _servicesmanager.Students.SaveStudentEditModelToDb(model); return(RedirectToAction("Index", "Students", new { studentId = model.StudentId })); }
public ActionResult Edit(StudentEditModel modelStudent) { var validImageTypes = new [] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (modelStudent.FilePicture != null && modelStudent.FilePicture.ContentLength > 0) { if (!validImageTypes.Contains(modelStudent.FilePicture.ContentType)) { ModelState.AddModelError("FilePicture", "Por favor seleccione entre una imagen GIF, JPG o PNG"); } } var myStudent = _studentRepository.GetById(modelStudent.Id); try { byte[] fileBytes = null; if (modelStudent.FilePicture != null) { using (var binaryReader = new BinaryReader(modelStudent.FilePicture.InputStream)) { fileBytes = binaryReader.ReadBytes(modelStudent.FilePicture.ContentLength); } } if (modelStudent.Tutor1 == null) { modelStudent.Tutor1 = myStudent.Tutor1; } if (modelStudent.Tutor2 == null) { modelStudent.Tutor2 = myStudent.Tutor2; } var studentModel = Mapper.Map <StudentEditModel, Student>(modelStudent); studentModel.MyGender = Implement.Utilities.DefineGender(modelStudent.MyGender); modelStudent.Photo = null; studentModel.Photo = fileBytes ?? myStudent.Photo; studentModel.MyUser = _parentRepository.GetById(modelStudent.Tutor1.Id).MyUser; myStudent = _studentRepository.UpdateStudentFromStudentEditModel(studentModel, myStudent); const string title = "Estudiante Actualizado"; var content = "El estudiante " + myStudent.FullName + " ha sido actualizado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.InformationMessage); return(RedirectToAction("Index")); } catch { modelStudent.MyGender = myStudent.MyGender.ToString("G").Substring(0, 1); modelStudent.FirstParent = myStudent.Tutor1.Id; modelStudent.Tutor1 = myStudent.Tutor1; modelStudent.Tutor2 = myStudent.Tutor2; if (myStudent.Tutor2 != null) { modelStudent.SecondParent = myStudent.Tutor2.Id; } ViewBag.Tutor1Id = new SelectList(_parentRepository.Query(x => x), "Id", "FullName", modelStudent.Tutor1.Id); if (modelStudent.Tutor2 == null) { modelStudent.Tutor2 = new Parent(); } ViewBag.Tutor2Id = new SelectList(_parentRepository.Query(x => x), "Id", "FullName", modelStudent.Tutor2.Id); return(View(modelStudent)); } }