public ActionResult Create([Bind(Include = "TeacherID,Salary,Name,Birthday")] Teacher teacher) { if (ModelState.IsValid) { service.CreateTeacher(teacher); return(RedirectToAction("Index")); } return(View(teacher)); }
public IActionResult CreateTeacher([FromBody] TeacherViewModel model) { Result <Teacher> result = _teacherService.CreateTeacher(model.FirstName, model.LastName); return(this.CreateResult <Teacher, TeacherViewModel>(result, o => { o.ToViewModel = t => t.ToTeacherViewModel(); o.RouteName = "GetTeacher"; o.RouteValues = t => new { id = t.TeacherId }; })); }
public IHttpActionResult Post(TeacherCreate teacher) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_teacherService.CreateTeacher(teacher)) { return(InternalServerError()); } return(Ok($"Teacher {teacher.FirstName} {teacher.LastName} was created")); }
public async Task <IActionResult> CreateTeacher([FromBody] TeacherDTO _TeacherDTO) { try { var teacher = await _teacherService.CreateTeacher(_TeacherDTO); return(Ok("Teacher Created")); } catch (Exception e) { return(BadRequest(e.Message)); } }
private void Save() { string szGender = string.Empty; string szBloodType = string.Empty; bool acad = false; if (cmbGender.Text == "Female") { szGender = "F"; } if (cmbGender.Text == "Male") { szGender = "M"; } if (cmbBloodType.Text == "A") { szBloodType = "A"; } if (cmbBloodType.Text == "O") { szBloodType = "O"; } if (cmbBloodType.Text == "AB") { szBloodType = "AB"; } if (cmbBloodType.Text == "A") { szBloodType = "A"; } if (radioAcademic.Checked == true && radioNonAcad.Checked == false) { acad = true; } else if (radioAcademic.Checked == false && radioNonAcad.Checked == true) { acad = false; } else if (radioAcademic.Checked == false && radioNonAcad.Checked == false) { acad = false; } Boolean ret = false; string message = String.Empty; byte[] bImage = null; if (pbImage.BackgroundImage != null) { bImage = imageToByteArray(pbImage.BackgroundImage, ImageFormat.Png); } TeacherService teacherService = new TeacherService(); String fName = txtFirstName.Text; String mName = txtMiddleName.Text; String lName = txtLastName.Text; String cName = fName.Trim() + mName.Trim() + lName.Trim(); var teachers = teacherService.GetAllTeachers(); teacherCompare = new List <Teacher>(teachers); Teacher teacher = new Teacher() { TeacherId = txtTeacherID.Text, BloodType = szBloodType, CivilStatus = cmbCivilState.Text, DOB = dtBirth.Value, DateOfAppointment = dtAppointment.Value, EmailAddress = txtEmailAdd.Text, EmploymentStatus = txtEmploymentState.Text, DialectSpoken = txtDialect.Text, FirstName = txtFirstName.Text, MiddleName = txtMiddleName.Text, LastName = txtLastName.Text, Gender = szGender, HeightCm = int.Parse(txtHeight.Text), WeightKg = double.Parse(txtWeight.Text), MobileNo = txtCellphone.Text, PAMunicipality = txtPA_Municipality.Text, PAProvince = txtPA_Province.Text, PARegion = cmbPA_Region.SelectedValue.ToString(), PAStreetName = txtPA_StreetName.Text, POBMunicipality = txtPOB_Municipality.Text, POBProvince = txtPOB_Province.Text, PagIBIGNo = txtPagIbig.Text, PhilHealthNo = txtPhilHealth.Text, PreviousSchool = txtSchoolReassigned.Text, RAMunicipality = txtRes_Municipality.Text, RAProvince = txtRes_Province.Text, RARegion = cmbRes_Region.SelectedValue.ToString(), RAStreetName = txtRes_StreetName.Text, ResTelephoneNo = txtRes_TelNo.Text, SSSNum = txtSSS.Text, SpouseBusinessAdd = txtSpouse_BusinessAdd.Text, SpouseEmployerName = txtSpouse_Employer.Text, SpouseFirstName = txtSpouse_FirstName.Text, SpouseLastName = txtSpouse_LastName.Text, SpouseMiddleName = txtSpouse_MiddleName.Text, SpouseOccupation = txtSpouse_Occupation.Text, SpouseTelephoneNo = txtSpouse_Contact.Text, TIN = txtTIN.Text, Image = bImage, PERAA = txtPERAA.Text, Academic = acad, Salary = double.Parse(txtSalary.Text), Department = txtDepartment.Text, TeacherChildrens = teachChild, TeacherEducationalBackgrounds = educBack, TeacherEligibilities = teachElig, WorkExperiences = workExp, TrainingSeminars = trainSem, }; if (Op.Equals("edit")) { ret = teacherService.UpdateTeacher(ref teacher, ref message); ILogService logService = new LogService(); teacher.TeacherChildrens = null; teacher.TeacherEducationalBackgrounds = null; teacher.TeacherEligibilities = null; teacher.TrainingSeminars = null; teacher.WorkExperiences = null; Log("U", "Teachers", teacher); foreach (TeacherChildren tc in teachChild) { Log("U", "TeacherChildren", tc); } foreach (TeacherEducationalBackground teb in educBack) { Log("U", "TeacherEducationalBackground", teb); } foreach (TeacherEligibility te in teachElig) { Log("U", "TeacherEligibilities", te); } foreach (WorkExperience we in workExp) { Log("U", "WorkExperiences", we); } foreach (TrainingSeminar ts in trainSem) { Log("U", "TrainingSeminars", ts); } } else { foreach (Teacher tc in teacherCompare) { String compareString = tc.FirstName.Trim() + tc.MiddleName.Trim() + tc.LastName.Trim(); if (cName.Equals(compareString)) { MessageBox.Show("Teacher already exist!"); break; } else { ret = teacherService.CreateTeacher(ref teacher, ref message); Log("C", "Teachers", teacher); } } } // if (ret) MessageBox.Show("Saved Successfully"); //else // MessageBox.Show("Error Saving"); Close(); }