//添加学生信息 public BaseViewModel addStudentInfo(StudentBaseModel student) { BaseViewModel viewModel = new BaseViewModel(); if (String.IsNullOrEmpty(student.Name) || String.IsNullOrEmpty(student.IdNumber) || String.IsNullOrEmpty(student.SchoolCode) || String.IsNullOrEmpty(student.GradeCode) || String.IsNullOrEmpty(student.ClassCode) || String.IsNullOrEmpty(student.PermanentAddress)) { viewModel.ResponseCode = 2; viewModel.Message = "参数信息为空"; } else { try { //验证 学校、年级、班级是否存在 if (_schoolInfoRepository.CheckInfo(student.SchoolCode, student.SchoolName)) { if (_gradeInfoRepository.CheckInfo(student.GradeCode, student.GradeName)) { if (_classInfoRepository.CheckInfo(student.ClassCode, student.ClassName)) { Student_Info info = new Student_Info(); info = _IMapper.Map <StudentBaseModel, Student_Info>(student); info.CreateDate = DateTime.Now; _studentInfoRepository.Add(info); _userInfoRepository.AddDefault(info.IdNumber);//创建默认账号 // _userInfoRepository int i = _studentInfoRepository.SaveChanges(); if (i > 0) { viewModel.ResponseCode = 0; viewModel.Message = "信息添加成功"; } else { viewModel.ResponseCode = 1; viewModel.Message = "信息添加失败"; } } else { viewModel.ResponseCode = 6; viewModel.Message = "班级信息不存在"; } } else { viewModel.ResponseCode = 5; viewModel.Message = "年级信息不存在"; } } else { viewModel.ResponseCode = 4; viewModel.Message = "学校信息不存在"; } } catch (Exception ex) { viewModel.ResponseCode = 3; viewModel.Message = "出现异常"; } } return(viewModel); }
public async Task <int> InsertStudent(object model) { int studentId; const string sql = @" INSERT INTO [dbo].[Students] ( [Created], [InitialMeeting], [FirstName], [MiddleName], [LastName], [StreetAddress], [StreetAddress2], [City], [State], [PostalCode], [Classification], [StudentId], [PhoneNumber], [LivingOnCampus], [EnrolledFullTime], [Citizenship], [PellGrantRecipient], [PassportHolder], [Gpa], [CampusEmail], [AlternateEmail], [EnteringYear], [GraduatingYear], [Dob], [PhiBetaDeltaMember] ) OUTPUT INSERTED.Id VALUES ( @Created, @InitialMeeting, @FirstName, @MiddleName, @LastName, @StreetAddress, @StreetAddress2, @City, @State, @PostalCode, @Classification, @StudentId, @PhoneNumber, @LivingOnCampus, @EnrolledFullTime, @Citizenship, @PellGrantRecipient, @PassportHolder, @Gpa, @CampusEmail, @AlternateEmail, @EnteringYear, @GraduatingYear, @DateOfBirth, @PhiBetaDeltaMember )"; try { StudentBaseModel baseModel = model as StudentBaseModel; if (baseModel.InitialMeeting.HasValue) { baseModel.InitialMeeting = baseModel.InitialMeeting.Value.ToUniversalTime(); } if (!string.IsNullOrEmpty(baseModel.MiddleName)) { baseModel.MiddleName = baseModel.MiddleName.CapitalizeFirstLetter(); } if (!string.IsNullOrEmpty(baseModel.PhoneNumber)) { baseModel.PhoneNumber = baseModel.PhoneNumber.Trim(); } if (!string.IsNullOrEmpty(baseModel.StudentId)) { baseModel.StudentId = baseModel.StudentId.Trim(); } if (baseModel.DateOfBirth.HasValue) { baseModel.DateOfBirth = baseModel.DateOfBirth.Value.ToUniversalTime(); } baseModel.CampusEmail = Formatter.SanitizeEmail(baseModel.CampusEmail); baseModel.AlternateEmail = Formatter.SanitizeEmail(baseModel.AlternateEmail); bool?phiBetaDeltaMember = null; if (model is StudentModel) { phiBetaDeltaMember = (model as StudentModel).PhiBetaDeltaMember; } studentId = (await UnitOfWork.Context().QueryAsync <int>(sql, new { Created = DateTime.Now.ToUniversalTime(), FirstName = baseModel.FirstName.CapitalizeFirstLetter(), LastName = baseModel.LastName.CapitalizeFirstLetter(), InitialMeeting = baseModel.InitialMeeting, MiddleName = baseModel.MiddleName, LivingOnCampus = baseModel.LivingOnCampus, StreetAddress = baseModel.StreetAddress, StreetAddress2 = baseModel.StreetAddress2, City = baseModel.City, State = baseModel.State, PostalCode = baseModel.PostalCode, PhoneNumber = baseModel.PhoneNumber, Classification = baseModel.Classification, EnteringYear = baseModel.EnteringYear, GraduatingYear = baseModel.GraduatingYear, StudentId = baseModel.StudentId, DateOfBirth = baseModel.DateOfBirth, Citizenship = baseModel.Citizenship, EnrolledFullTime = baseModel.EnrolledFullTime, PellGrantRecipient = baseModel.PellGrantRecipient, PassportHolder = baseModel.HasPassport, CampusEmail = baseModel.CampusEmail, AlternateEmail = baseModel.AlternateEmail, PhiBetaDeltaMember = phiBetaDeltaMember, Gpa = baseModel.Gpa })).Single(); await SaveAssociatedTables(studentId, baseModel.SelectedMajors, baseModel.SelectedMinors, baseModel.StudyAbroadCountry, baseModel.StudyAbroadYear, baseModel.StudyAbroadPeriod, baseModel.SelectedLanguages, baseModel.SelectedDesiredLanguages, baseModel.StudiedLanguages); } catch (Exception e) { e.Data["SQL"] = sql.ToString(); ErrorStore.LogException(e, HttpContext.Current); throw e; } return(studentId); }
public ActionResult <BaseViewModel> addStudentInfo(StudentBaseModel student) { BaseViewModel viewModel = _studentService.addStudentInfo(student); return(viewModel); }