public string AddNewTeacher(string Name, string Surname, string PassportNomber, int IdSchool) { if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Surname) || string.IsNullOrEmpty(PassportNomber)) { return("All Informations Of Teacher Not Allow To be Empty"); } else { if (_dalschool.IsExist(IdSchool)) { if (!_dal.IsExist(Name, Surname)) { var teacher = Teacher.CreaTeacher(Name, Surname, PassportNomber); _dal.AddNewTeacher(teacher); var School = _dalschool.GetSchool(IdSchool); _dal.AddNewTeacherSchool(TeacherSchool.CreaTeacherSchool(School, teacher)); return("true"); } else { return("This Teacher Is Exist Before"); } } else { return("This School Is Not Exist "); } } }
public async Task <ActionResult> AddTeacherSchool([FromForm] TeacherSchool teacherSchool) { if (!ModelState.IsValid) { ModelState.AddModelError("ErrorMessage:", "You unAuthorize to Get Data of this Teacher"); return(BadRequest(ModelState)); } var identity = User.Identity as ClaimsIdentity; if (identity == null) { ModelState.AddModelError("ErrorMessage:", "You are not Authanticated"); return(BadRequest(ModelState)); } IEnumerable <Claim> claims = identity.Claims; var teacherId = claims.Where(p => p.Type == "TeacherId").FirstOrDefault()?.Value; if (teacherId == null) { ModelState.AddModelError("ErrorMessage:", "You are not Authanticated"); return(BadRequest(ModelState)); } await _teacherSchoolRepository.AddTeacherSchool(teacherSchool); return(Created("TeacherSchoolTable", teacherSchool)); }
public async Task <IActionResult> DeleteTeacherSchool(int teacherSchoolId) { TeacherSchool teacherSchoolById = await _teacherSchoolRepository.GetTeacherSchoolById(teacherSchoolId); if (teacherSchoolById == null) { return(Content("not found , please Check!...")); } await _teacherSchoolRepository.DeleteTeacherSchool(teacherSchoolById); return(Ok("Deleted Successfully")); }
public string AddTeacherToSchool(int IdSchool, int IdTeacher) { if (_dal.IsExist(IdTeacher)) { if (_dalschool.IsExist(IdSchool)) { var School = _dalschool.GetSchool(IdSchool); var Teacher = _dal.GetTeaher(IdTeacher); _dal.AddNewTeacherSchool(TeacherSchool.CreaTeacherSchool(School, Teacher)); return("true"); } else { return("This Teacher Is Exist Before"); } } else { return("This School Is Not Exist "); } }
// Delete TeacherSchool public async Task DeleteTeacherSchool(TeacherSchool teacherSchool) { _context.TeacherSchools.Remove(teacherSchool); await _context.SaveChangesAsync(); }
// Add new TeacherSchool public async Task AddTeacherSchool(TeacherSchool teacherSchool) { await _context.TeacherSchools.AddAsync(teacherSchool); await _context.SaveChangesAsync(); }