Note: i have uploaded CSV file by using above code and Read& Validate the data also , but i am unable to save those records into db. can any one can help me to pass data from my service.ts to webpapi controllers action method.
Bellow code is html code for csv fileupload -
<td><input type="file" name="File Upload" id="txtFileUpload"
(change)="changeListener($event.target.files)"
accept=".csv"/></td>
<td> <button class="btn btn1 btn2" color="primary" mat-raised-button *ngIf="isUploadFile" (click)="uploadCSVFile($event)">
UploadFile
</button></td>
Bellow code is Component.ts code -
uploadCSVFile($event) {
event.preventDefault();
alert('upload');
let businessAccountData = this.csvRecords;
let merchantdata: UserMerchantData = this.commonfunction.getUserMerchantData();
let email = this.commonfunction.getEmail();
// let userName = this.commonfunction.getUserName();
// for(let i =1; i<= businessAccountData.length;i++)
// {
// businessAccountData[i].UserName =userName;
// businessAccountData[i].MerchantKeyId =merchantdata.MerchantKeyId;
// }
this.service.addOnBusinessAccountData(businessAccountData,email).subscribe(result => {
console.log(' result - ', result);
if (result != null) {
//this.router.navigate(['/home/addonBusiness/manage-business-accounts']);
}
});
}
below code is service.ts file -
**strong text**
addOnBusinessAccountData(data,email)
{
alert('service');
// alert(JSON.stringify(data));
alert(data);
return this.service.create(environment.createBusinessAccountDataUrl+"?email="+email, data);
}
below code is for webapi controller's action method -
[HttpPost]
public IHttpActionResult AddAccountData(AddOnAccountData[] addOnAccountData, string email)
{
try
{
_apiConnectivity = new VposApiConnnectivity(email);
var businessAccountResponse = _apiConnectivity.AddAccountData(addOnAccountData);
return Json(businessAccountResponse);
}
catch (Exception e)
{
return Ok("");
}
}