public int AddEducationTitles(EducationTitles data) { var checkNumber = _context.EducationTitles.Any(x => x.educationId == data.educationId && x.academicTitlesId == data.academicTitlesId); if (checkNumber) { return(-1); } var res = _context.EducationTitles.Add(data); _context.SaveChanges(); return(res.Entity.Id); }
public IActionResult PutEducationTitles(int id, [FromBody] EducationTitles data) { try { var res = _repository.UpdateEducationTitles(id, data); if (!res) { return(Conflict(409)); } return(Ok(res)); } catch (Exception error) { return(BadRequest(error)); } }
public IActionResult PostEducationTitles(EducationTitles data) { try { var res = _repository.AddEducationTitles(data); if (res == -1) { return(Conflict(409)); } return(Ok(res)); } catch (Exception error) { return(BadRequest(error)); } }
public bool UpdateEducationTitles(int id, EducationTitles data) { var res = _context.EducationTitles.FirstOrDefault(x => x.Id == id); if (res == null) { return(false); } var checkNumber = _context.EducationTitles.Where(x => x.Id != id).Any(x => x.educationId == data.educationId && x.academicTitlesId == data.academicTitlesId); if (checkNumber) { return(false); } res.educationId = data.educationId; res.academicTitlesId = data.academicTitlesId; _context.SaveChanges(); return(true); }