Exemple #1
0
 public void UpdateApplicant(int id, BusinessApplicant updatedApplicant)
 {
     try
     {
         var applicant = _context.Applicants.FirstOrDefault(applicant => applicant.ID == id);
         _context.Update(applicant);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
 public IActionResult Put(int id, [FromBody] BusinessApplicant value)
 {
     try
     {
         _applicantService.UpdateApplicant(id, value);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest($"Bad Request {ex.Message}"));
     }
 }
        public IActionResult Post([FromBody] BusinessApplicant applicant)
        {
            BusinessApplicant newApplicant = applicant;

            try
            {
                // Cerate the new applicant and get its id.
                int newID = _applicantService.CreateApplicant(newApplicant);
                // Send the url back to the client with the newly created applicant's id.
                return(CreatedAtAction(nameof(ApplicantController.Get), new { id = newID }, null));
            }
            catch (Exception ex)
            {
                return(BadRequest($"bad request: {ex.Message}"));
            }
        }
Exemple #4
0
        public BusinessApplicant GetApplicant(int id)
        {
            try
            {
                BusinessApplicant applicant = _context.Applicants.Where(applicant => applicant.ID == id)
                                              .Select(applicant => new BusinessApplicant
                {
                    Name            = applicant.Name,
                    FamilyName      = applicant.FamilyName,
                    EmailAddress    = applicant.EmailAddress,
                    Address         = applicant.Address,
                    CountryOfOrigin = applicant.CountryOfOrigin,
                    Age             = applicant.Age,
                    Hired           = applicant.Hired
                }).FirstOrDefault();

                return(applicant);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #5
0
 public int CreateApplicant(BusinessApplicant applicant)
 {
     try
     {
         Applicant newApplicant = new Applicant
         {
             Name            = applicant.Name,
             FamilyName      = applicant.FamilyName,
             Address         = applicant.Address,
             Age             = applicant.Age,
             CountryOfOrigin = applicant.CountryOfOrigin,
             EmailAddress    = applicant.EmailAddress,
             Hired           = applicant.Hired
         };
         _context.Add(newApplicant);
         _context.SaveChanges();
         return(newApplicant.ID);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }