Example #1
0
 private bool CheckFileTransferRequest(FileTransferRequest fileToPush, out string message)
 {
     if (fileToPush != null)
     {
         if (!string.IsNullOrEmpty(fileToPush.FileName))
         {
             if (fileToPush.Content != null)
             {
                 message = "File transfered";
                 return(true);
             }
             else
             {
                 message = "File is empty";
                 return(false);
             }
         }
         else
         {
             message = "File is empty";
             return(false);
         }
     }
     else
     {
         message = "File not found";
         return(false);
     };
 }
Example #2
0
        public List <MunicipalityTaxResponse> UploadDataFromFile(FileTransferRequest inputFile)
        {
            List <MunicipalityTaxResponse> TaxRecordList = new List <MunicipalityTaxResponse>();
            MunicipalityTaxResponse        TaxRecord     = new MunicipalityTaxResponse();

            if (!CheckFileTransferRequest(inputFile, out string message))
            {
                TaxRecord.Status  = false;
                TaxRecord.Message = message;
                TaxRecordList.Add(TaxRecord);
                return(TaxRecordList);
            }

            try
            {
                if (SaveFileStream(inputFile.FileName, new MemoryStream(inputFile.Content), out message))
                {
                    DataTable records = GetDataFromCSV(inputFile.FileName);

                    foreach (DataRow rec in records.Rows)
                    {
                        TaxRecord = new MunicipalityTaxResponse();
                        if (!bool.Parse(rec[5].ToString()))
                        {
                            TaxRecord.Status  = bool.Parse(rec[5].ToString());
                            TaxRecord.Message = rec[6].ToString();
                        }
                        else
                        {
                            try
                            {
                                TaxRecord.Municipality = rec[0].ToString();
                                TaxRecord.TaxType      = rec[1].ToString();
                                TaxRecord.ValidFrom    = DateTime.Parse(rec[2].ToString());
                                TaxRecord.ValidTo      = DateTime.Parse(rec[3].ToString());
                                TaxRecord.Tax          = Decimal.Parse(rec[4].ToString());
                                GeneralResponse res = AddTaxRecord(TaxRecord);
                                TaxRecord.Status  = res.status;
                                TaxRecord.Message = res.message;
                            }
                            catch
                            {
                                TaxRecord.Status  = false;
                                TaxRecord.Message = "Unable to convert field data";
                            }
                        }
                        TaxRecordList.Add(TaxRecord);
                    }
                }
                else
                {
                    TaxRecord.Status  = false;
                    TaxRecord.Message = message;
                    TaxRecordList.Add(TaxRecord);
                    return(TaxRecordList);
                }
            }
            catch
            {
                TaxRecord.Status  = false;
                TaxRecord.Message = "Unknown file format";
                TaxRecordList.Add(TaxRecord);
                return(TaxRecordList);
            }

            return(TaxRecordList);
        }