private JsonResult SaveNonEmployee(SaveNonEmployeeRequest saveNonEmployeeRequest)
        {
            var result = _nonEmployeeSaveTask.Execute(saveNonEmployeeRequest);
            if (!result.Success)
            {
                return Json(new { Success = false, result.Message, result.Matches });
            }

            return Json(new { Success = true, NonEmployeeId = result.Id });
        }
        public CompanyDefaultSaveResponse Execute(SaveNonEmployeeRequest request)
        {
            if (request.RunMatchCheck)
            {
                var nonEmployeeDefaultAlreadyExistGuard = new GuardDefaultExistsRequest(request.Name, request.Id, request.CompanyId);
                var existResult = _nonEmployeeDefaultAlreadyExistGuard.Execute(nonEmployeeDefaultAlreadyExistGuard);

                if (existResult.Exists)
                {
                    return CompanyDefaultSaveResponse.CompanyDefaultMatches(existResult.MatchingResults);
                }
            }

            return _nonEmployeeService.SaveNonEmployee(request);
        }
 public JsonResult UpdateNonEmployee(long nonEmployeeId, long companyIdLink, string name, string position, string companyName, bool runMatchCheck)
 {
     var updateNonEmployeeRequest = new SaveNonEmployeeRequest(nonEmployeeId, companyIdLink, name, position, companyName, runMatchCheck, CurrentUser.UserId);
     return SaveNonEmployee(updateNonEmployeeRequest);
 }
        public CompanyDefaultSaveResponse SaveNonEmployee(SaveNonEmployeeRequest request)
        {
            _log.Add(request);

            try
            {
                var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);

                NonEmployee nonEmployee;
                if (request.Id == 0)
                {
                    nonEmployee = NonEmployee.Create(request.Name, request.Position, request.NonEmployeeCompanyName, request.CompanyId, user);
                }
                else
                {
                    nonEmployee = _nonEmployeeRepository.GetByIdAndCompanyId(request.Id, request.CompanyId);
                    nonEmployee.Update(request.Name, request.Position, request.NonEmployeeCompanyName, user);
                }

                _nonEmployeeRepository.SaveOrUpdate(nonEmployee);


                return CompanyDefaultSaveResponse.CreateSavedSuccessfullyResponse(nonEmployee.Id);
            }
            catch (Exception ex)
            {
                _log.Add(ex);
                throw;
            }

           

        }