public MunicipalityTaxResponse GetTaxInfo(MunicipalityTax req) { MunicipalityTaxResponse tbl = new MunicipalityTaxResponse(); using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand sqlCommand = new SqlCommand()) { sqlCommand.CommandText = @"SELECT TOP 1 tax FROM municipalities LEFT JOIN TaxPriorities ON municipalities.tax_type = TaxPriorities.TaxType where municipality = @parMunicip and valid_from <= @parDate and valid_to >= @parDate ORDER BY Priority"; sqlCommand.Parameters.Add(new SqlParameter("parMunicip", req.Municipality)); sqlCommand.Parameters.Add(new SqlParameter("parDate", req.ValidFrom)); sqlCommand.Connection = connection; connection.Open(); try { sqlCommand.ExecuteNonQuery(); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { if (reader.Read()) { tbl.Status = true; tbl.Tax = reader.GetDecimal(0); tbl.Message = ""; } else { tbl.Status = false; tbl.Tax = 0; tbl.Message = "No tax records found"; } } } catch { tbl.Status = false; tbl.Tax = 0; tbl.Message = "Database error occured"; } } } return(tbl); }
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); }