Exemplo n.º 1
0
        public async Task <IActionResult> Update([Required] int id, Applicants applicants)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = new TaskResult <Applicants>();

            if (id != applicants.Id)
            {
                result.AddErrorMessage("Los identificadores no coinciden");
                return(Ok(result));
            }

            result = _applicantsRepository.Update(applicants);
            await _applicantsRepository.SaveAsync();

            return(Ok(result));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(Applicants applicants)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var resultApplicant = await _applicantsRepository.GetByIdAsync(applicants.Id);

            var applicant   = resultApplicant.Data;
            var newEmployee = new Employees();

            if (resultApplicant.Success)
            {
                applicant.Status = (int)Enums.Entities.Status.DISABLE;
                _applicantsRepository.Update(applicant);

                newEmployee.JobPositionsId  = applicant.JobPositionsId;
                newEmployee.MonthSalary     = applicant.SalaryAspiration;
                newEmployee.Name            = applicant.Name;
                newEmployee.DocumentNumber  = applicant.DocumentNumber;
                newEmployee.DateOfAdmission = DateTime.Now;
                newEmployee.Department      = applicant.Department;
            }
            var result = new TaskResult <bool>();

            try
            {
                await _genericRepository.CreateAsync(newEmployee);

                result.Data = await _genericRepository.SaveAsync();
            }
            catch (Exception e)
            {
                result.AddErrorMessage(e.Message);
            }

            return(Ok(result));
        }