public int AddRecruitment(RecruitmentInfoDataModel data)
        {
            var existEmployee = _context.Employees.FirstOrDefault(x => x.Id == data.EmployeeId);

            if (existEmployee == null)
            {
                return(-1);
            }

            var checkRecruitment = _context.Recruitment.Any(x => x.employeeId == data.EmployeeId && !x.Deleted);

            var checkDismissal = _context.Dismissal.Any(x => x.employeeId == data.EmployeeId && !x.deleted);

            if (!checkDismissal && checkRecruitment)
            {
                return(-3);
            }

            var res = _context.Recruitment.Add(new Recruitment()
            {
                employeeId            = data.EmployeeId,
                dateOfReceipt         = data.DateOfReceipt,
                positionId            = data.PositionId,
                unitId                = data.UnitId,
                sheduleId             = data.SheduleId,
                typeOfEmploymentId    = data.TypeOfEmploymentId,
                probation             = data.Probation,
                vacationEntitlementId = data.Vacation.VacationEntitlementId,
                vacationDays          = data.Vacation.VacationDays,
                Salary                = new DataModel.Salary()
                {
                    salary = data.Salary.Value
                },
                Contract = new DataModel.Contract()
                {
                    dateStart = data.Contract.StartDate,
                    dateEnd   = data.Contract.FinishDate,
                    number    = data.Contract.ContractNumber,
                    rate      = data.Salary.Rates
                }
            });

            existEmployee.StatusId = 2;

            _context.SaveChanges();

            return(res.Entity.Id);
        }
        public IActionResult PutRecruitment(int id, [FromBody] RecruitmentInfoDataModel data)
        {
            try
            {
                var res = _repository.UpdateRecruitment(id, data);

                if (!res)
                {
                    return(Conflict(409));
                }

                return(Ok(res));
            }
            catch (Exception error)
            {
                return(BadRequest(error));
            }
        }
        public IActionResult PostRecruitment(RecruitmentInfoDataModel data)
        {
            try
            {
                var res = _repository.AddRecruitment(data);

                if (res == -1)
                {
                    return(Conflict("Такого сотрудника не существует!"));
                }

                if (res == -3)
                {
                    return(Conflict("Сотрудник еще не уволен!"));
                }

                return(Ok(res));
            }
            catch (Exception error)
            {
                return(BadRequest(error));
            }
        }
        public bool UpdateRecruitment(int id, RecruitmentInfoDataModel data)
        {
            var existEmployee = _context.Employees.FirstOrDefault(x => x.Id == id);

            if (existEmployee == null)
            {
                return(false);
            }

            var existRecruitment = _context.Recruitment.Include(x => x.Salary).Include(x => x.Contract).FirstOrDefault(x => x.employeeId == id && !x.Deleted);

            var checkDismissal = _context.Dismissal.Any(x => x.employeeId == data.EmployeeId && !x.deleted);

            if (!checkDismissal && existRecruitment == null)
            {
                return(false);
            }

            existRecruitment.dateOfReceipt         = data.DateOfReceipt;
            existRecruitment.positionId            = data.PositionId;
            existRecruitment.unitId                = data.UnitId;
            existRecruitment.sheduleId             = data.SheduleId;
            existRecruitment.typeOfEmploymentId    = data.TypeOfEmploymentId;
            existRecruitment.probation             = data.Probation;
            existRecruitment.vacationEntitlementId = data.Vacation.VacationEntitlementId;
            existRecruitment.vacationDays          = data.Vacation.VacationDays;
            existRecruitment.Salary.salary         = data.Salary.Value;
            existRecruitment.Contract.dateStart    = data.Contract.StartDate;
            existRecruitment.Contract.dateEnd      = data.Contract.FinishDate;
            existRecruitment.Contract.number       = data.Contract.ContractNumber;
            existRecruitment.Contract.rate         = data.Salary.Rates;

            _context.SaveChanges();

            return(true);
        }