コード例 #1
0
        public void Delete(EngineerDegrees ec)
        {
            var targetEngCert = this.GetByKey(ec);

            _context.EngineerDegrees.Remove(targetEngCert);
            _context.SaveChanges();
        }
コード例 #2
0
 public IActionResult GetEngineerCertification([FromBody] EngineerDegrees ec)
 {
     try{
         var targetEngCert = _engineerDegService.GetByKey(ec);
         return(Ok(targetEngCert));
     }
     catch (AppException ex) {
         return(BadRequest(new { message = ex.Message }));
     }
 }
コード例 #3
0
        public void Update(string newDegVal, EngineerDegrees oldDeg)
        {
            EngineerDegrees newDeg = new EngineerDegrees();

            newDeg.Email  = oldDeg.Email;
            newDeg.Degree = newDegVal;
            Delete(oldDeg);
            Create(newDeg);
            _context.SaveChanges();
        }
コード例 #4
0
 public IActionResult Delete([FromBody] EngineerDegrees ec)
 {
     try{
         _engineerDegService.Delete(ec);
         return(Ok(ec));
     }
     catch (AppException ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }
コード例 #5
0
 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 }));
     }
 }
コード例 #6
0
 public IActionResult Create([FromBody] EngineerDegrees ec)
 {
     try
     {
         var newEngCert = _engineerDegService.Create(ec);
         return(Ok(newEngCert));
     }
     catch (AppException ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }
コード例 #7
0
        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.");
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }