public Response UpdtateApplicantById(int id, ApplicantModel applicant)
        {
            Response response       = _utilities.InitializeResponse();
            var      applicantFound = _applicantRepository.GetApplicantByID(id);

            applicantFound.Name            = applicant.Name;
            applicantFound.FamilyName      = applicant.FamilyName;
            applicantFound.Address         = applicant.Address;
            applicantFound.Age             = applicant.Age;
            applicantFound.CountryOfOrigin = applicant.CountryOfOrigin;
            applicantFound.EMailAdress     = applicant.EMailAdress;
            applicantFound.Hired           = applicant.Hired;

            if (applicantFound == null)
            {
                return(_utilities.UnsuccessfulResponse(response, "Invalid id supplied. Could not match applicant to id"));
            }
            try
            {
                // Update and save changes
                _applicantRepository.UpdateApplicant(applicantFound);
                _applicantRepository.Save();
            }
            catch (Exception ex)
            {
                return(_utilities.CatchException(ex, response));
            }

            response.Data = _applicantRepository.GetApplicantByID(id);

            _logger.LogInformation($"Successfully updated {id}");

            return(response);
        }
        public IActionResult Edit(int id, [Bind("Id,Name,Address,PhoneNumber,Email")] Applicant applicant)
        {
            if (id != applicant.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _applicantRepository.UpdateApplicant(applicant);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ApplicantExists(applicant.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(applicant));
        }
예제 #3
0
        public async Task <IActionResult> UpdateApplicant([FromBody] Applicant applicant)
        {
            _logger.LogInformation("\t\n\n=========================================================================\n\nAccessing the Endpoint for Updating an Applicant");
            try
            {
                var validationResult = _applicantValidator.Validate(applicant);
                if (!validationResult.IsValid)
                {
                    _logger.LogInformation("Update Endpoint called with invalid parameters");
                    return(BadRequest(new ResponseModel(400, "object has one or more validation Errors", validationResult.Errors)));
                }
                var updateResult = await _appRepository.UpdateApplicant(applicant);

                if (updateResult > 0)
                {
                    _logger.LogInformation("Successful Update call was made");
                    return(Ok(new ResponseModel(200, "Applicant updated", applicant)));
                }
                _logger.LogInformation("Update call was not successful");
                return(BadRequest(new ResponseModel(400, "Failed", applicant)));
            }
            catch (Exception ex)
            {
                _logger.LogInformation("An Error occured in the Update endpoint", ex);
                return(BadRequest(new ResponseModel(400, "Some Error occuredl!!! Please Try again", null)));
            }
        }
예제 #4
0
 public ActionResult <ApplicantDTO> Update([FromBody] ApplicantDTO dto)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _logger.LogInformation($"Updating record with name {dto.Name} ");
             _repo.UpdateApplicant(dto);
             _message = $"Record updated successfully with name {dto.Name} ";
             _logger.LogInformation(_message);
             return(Ok(_message));
         }
         catch (Exception ex)
         {
             _logger.LogInformation($"Failed to update record with name {dto.Name}, Error {ex.Message}");
             return(BadRequest(ex));
         }
     }
     else
     {
         StringBuilder errors = Errors();
         _logger.LogInformation($"Validation errors for record with name {dto.Name} erros : {errors} ");
         return(BadRequest(errors));
     }
 }
예제 #5
0
 public ActionResult Edit([Bind(Include = "ApplicantId,ApellidoParterno,ApellidoMaterno,Nombre,FechaNacimiento,DomicilioId,Nacionalidad,Rfc,Curp")] Applicant applicant)
 {
     if (ModelState.IsValid)
     {
         _repository.UpdateApplicant(applicant);
         return(RedirectToAction("Index"));
     }
     return(View(applicant));
 }
예제 #6
0
        public async Task <IActionResult> UpdateApplicant(int id, ApplicantModel applicantModel)
        {
            var update_applicant = await _applicantRepository.UpdateApplicant(id, applicantModel);

            if (update_applicant > 0)
            {
                return(Ok(update_applicant));
            }
            else
            {
                return(BadRequest());
            }
        }
        public async Task <ActionResult <Applicant> > UpdateApplicant(int id, Applicant applicant)
        {
            try
            {
                var applicantToUpdate = await applicantRepository.GetApplicant(id);

                if (applicantToUpdate == null)
                {
                    Log.Error($"{Section.GetValue<string>("NotFound")}[object=Applicant; id={id}]");
                    return(NotFound($"Applicant with id= {id} not found"));
                }
                Log.Information($"[object=Applicant; id={id}] has been updated");
                Log.Debug($"Updated object: [{applicantToUpdate}]");
                return(await applicantRepository.UpdateApplicant(applicant));
            }
            catch (Exception err)
            {
                Log.Error($"Exception occured: [{err}]\nStatusCode:{Code500}");
                return(StatusCode(Code500, Section.GetValue <string>("RetreiveFromDbError")));
            }
        }
        public IActionResult PutApplicant([FromBody] Applicant applicant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!ApplicantExists(applicant.ApplicantCode))
            {
                return(BadRequest());
            }

            if (applicant != null)
            {
                try
                {
                    using (var scope = new TransactionScope())
                    {
                        _context.UpdateApplicant(applicant);
                        scope.Complete();
                        return(new OkResult());
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ApplicantExists(applicant.ApplicantCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(new NoContentResult());
        }
        public async Task <ActionResult <Applicant> > UpdateApplicant(int ID, Applicant applicant)
        {
            try
            {
                if (ID != applicant.ID)
                {
                    return(BadRequest("Wrong applicant ID"));
                }

                var applicantToUpdate = await applicantRepository.GetApplicant(ID);

                if (applicantToUpdate == null)
                {
                    return(NotFound($"Applicant with id = {ID} not found"));
                }

                return(await applicantRepository.UpdateApplicant(applicant));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Updating applicant error!"));
            }
        }
 public int UpdateApplicant(int applicantID, Dto.Model.Applicant applicant)
 {
     return(_applicantRepository.UpdateApplicant(applicantID, applicant.MapToData()));
 }
예제 #11
0
 public void UpdateApplicant(ApplicantDto applicantDto)
 {
     _applicantRepository.UpdateApplicant(_mapper.Map <ApplicantDto, Applicant>(applicantDto));
 }
예제 #12
0
 public int UpdateApplicant(Applicant objApplicant)
 {
     return(_applicantRepository.UpdateApplicant(objApplicant));
 }