public async Task <ActionResult> AddTeacherEduction([FromForm] TeacherEduction teacherEduction) { 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 _teacherEductionRepository.AddTeacherEduction(teacherEduction); return(Created("TeacherEductionTable", teacherEduction)); }
public async Task <IActionResult> DeleteTeacherEduction(int teacherEducationId) { TeacherEduction teacherEductionById = await _teacherEductionRepository.GetTeacherEductionById(teacherEducationId); if (teacherEductionById == null) { return(Content("not found , please Check!...")); } else { await _teacherEductionRepository.DeleteTeacherEduction(teacherEductionById); return(Ok("Deleted Successfully")); } }
// Delete TeacherEduction public async Task DeleteTeacherEduction(TeacherEduction teacherEduction) { _context.TeacherEductions.Remove(teacherEduction); await _context.SaveChangesAsync(); }
// Add new TeacherEduction public async Task AddTeacherEduction(TeacherEduction teacherEduction) { await _context.TeacherEductions.AddAsync(teacherEduction); await _context.SaveChangesAsync(); }