Не удалось получить функцию post при передаче данных Excel из функции angularjs в c# через webapi - PullRequest
0 голосов
/ 03 апреля 2020

Метод Post Web API использует функцию c# UploadExpatData без передачи параметра deductionfiledata, но не выполняет функцию c# при передаче параметра deductionfiledata.

Angula Js код:

           $scope.UploadExpatAttendanceFile = function (value) {
             SharedService.BlockUI();
             if (value == 1)
              { var attachment = document.getElementById('ExpatFile').files[0]; }
                var deductiontype = value;
                var reader = new FileReader();
                var newElement = new Object();
                reader.onload = function (e) {
                PayrollDetailService.UploadExpatFile(e.target.result, deductiontype).then(function 
                (response) {
                 if (response.data.Status == 'Success') {
                 SharedService.UnBlockUI();
                 $scope.DisplayAttendanceMessage('Upload successful for ' + 
                 response.data.Data.toString() + ' employees', true, true);
                }
                 else {
                        SharedService.UnBlockUI();
                        $scope.DisplayAttendanceMessage('Upload Aborted: ' + response.data.Message, 
                        false, true);
                      }
                });
              }
            $('#ExpatFile')[0].value = ''
            reader.readAsDataURL(attachment);
            attachment = null;
          }

Функция UploadExpatFile находится в PayrollDetailService. js file

           UploadExpatFile: function (deductionfiledata, deductiontype) {                                                                                                       
                  var deferred = $q.defer();
                  $http({
                         url: '../Api/PayrollConfig/UploadExpatData?filedata=' + deductionfiledata + 
                              '&deductionstype=' + deductiontype,
                         method: "POST",
                         cache: false
                        }).then(function (data) {
                          //success
                          deferred.resolve(data);
                        }, function (status) {
                          //error
                          deferred.reject(status);
                          SharedService.LogError("Error occured in UploadDeductionsFile method of 
                          config-attendance-service js");
                        });
                          return deferred.promise;
                        },

и C# Функция -

         [System.Web.Http.HttpPost]
         public JSONResponse<int?> UploadExpatData(string filedata, int deductionstype)
          {
           JSONResponse<int?> returnobject = new JSONResponse<int?>();
           try
            {
             string newDoc = filedata.Split(';')[1].Replace("base64,", "");
             byte[] data = Convert.FromBase64String(newDoc);
             EmployeeDeductions employeededuction = new EmployeeDeductions();
             int count = employeededuction.UploadExpatEmployeeData(data,
             "ManualUploadExpatAttendance", deductionstype);
             return returnobject.SetValues("Success", count, "");
             }
            catch (Exception ex)
             {
              Logger.Error("Error occured in UploadDeductionsData in DeductionConfigController", ex);
              return returnobject.SetValues("Error", 0, ex.Message);
             }
            }
...