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