Exemplo n.º 1
0
        public virtual ActionResult UploadInvoice(HttpPostedFileBase invoiceFile)
        {
            LogI("UploadInvoice");
            try
            {
                if (invoiceFile != null)
                {
                    LogI("fileLength=" + invoiceFile.ContentLength + ", fileName=" + invoiceFile.FileName);
                    if (invoiceFile.ContentLength > 0)
                    {
                        var fileName   = Path.GetFileName(invoiceFile.FileName);
                        var folderPath = Models.UrlHelper.GetUploadDhlInvoicePath();
                        var filePath   = Path.Combine(folderPath, fileName);
                        invoiceFile.SaveAs(filePath);

                        var dhlService = new DhlInvoiceService(LogService, Time, DbFactory);
                        var records    = dhlService.GetRecordsFromFile(filePath);
                        dhlService.ProcessRecords(records, ShipmentProviderType.Dhl);

                        return(Json(MessageResult.Success("Invoice file has been processed")));
                    }
                }

                return(Json(MessageResult.Error("Empty file")));
            }
            catch (Exception ex)
            {
                LogE("UploadInvoice, file=" + invoiceFile.FileName, ex);
                return(Json(MessageResult.Error(ex.Message)));
            }
        }
 public void Process(IUnitOfWork db,
                     EmailReadingResult result)
 {
     if (result.Status == EmailMatchingResultStatus.New &&
         result.Email.Type == (int)IncomeEmailTypes.DhlInvoice)
     {
         var attachment = result.Email.Attachments.FirstOrDefault();
         if (attachment != null)
         {
             _log.Info("Process DHL Invoice, path=" + attachment.PhysicalPath);
             var dhlService = new DhlInvoiceService(_log, _time, _dbFactory);
             var records    = dhlService.GetRecordsFromFile(attachment.PhysicalPath);
             dhlService.ProcessRecords(records, ShipmentProviderType.Dhl);
         }
     }
 }