public void Delete(EngineerDegrees ec) { var targetEngCert = this.GetByKey(ec); _context.EngineerDegrees.Remove(targetEngCert); _context.SaveChanges(); }
public IActionResult GetEngineerCertification([FromBody] EngineerDegrees ec) { try{ var targetEngCert = _engineerDegService.GetByKey(ec); return(Ok(targetEngCert)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public void Update(string newDegVal, EngineerDegrees oldDeg) { EngineerDegrees newDeg = new EngineerDegrees(); newDeg.Email = oldDeg.Email; newDeg.Degree = newDegVal; Delete(oldDeg); Create(newDeg); _context.SaveChanges(); }
public IActionResult Delete([FromBody] EngineerDegrees ec) { try{ _engineerDegService.Delete(ec); return(Ok(ec)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public IActionResult Update(string newDegVal, [FromBody] EngineerDegrees oldDeg) { try{ Console.WriteLine($"The newCertVal:{newDegVal}"); _engineerDegService.Update(newDegVal, oldDeg); return(Ok(new { message = "Updated." })); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public IActionResult Create([FromBody] EngineerDegrees ec) { try { var newEngCert = _engineerDegService.Create(ec); return(Ok(newEngCert)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public void CheckValues(EngineerDegrees ec) { if (string.IsNullOrWhiteSpace(ec.Email)) { throw new AppException("Email is required to finish inserting this record."); } if (string.IsNullOrWhiteSpace(ec.Degree)) { throw new AppException("Degree is required to be entered into this field."); } }
public EngineerDegrees GetByKey(EngineerDegrees ec) { CheckValues(ec); var targetEngCert = _context.EngineerDegrees.SingleOrDefault(x => (x.Degree == ec.Degree && x.Email == ec.Email)); if (targetEngCert == null) { throw new AppException($"Degree with email:'{ec.Email}' and Degree:'{ec.Degree}' DNE."); } return(targetEngCert); }
public EngineerDegrees Create(EngineerDegrees ec) { var checkObj = _context.EngineerDegrees.SingleOrDefault(x => x.Email == ec.Email && x.Degree == ec.Degree); if (checkObj != null) { throw new AppException($"Engineer Degree already exists for Email:{ec.Email} and Degree:{ec.Degree}"); } this.CheckValues(ec); _context.EngineerDegrees.Add(ec); _context.SaveChanges(); return(ec); }