private MasterDataValidationAndImportResponse GenerateResponse(MasterDataImportResponse res) { var response=new MasterDataValidationAndImportResponse(); if (res == null) return response; response.ValidationResults = res.ValidationResults .Select(n => new StringifiedValidationResult() { Results = n.Results.Select( p => p.ErrorMessage).ToList(), Entity = n.EntityItem, Description = n.Description, IsValid = n.IsValid }).ToList(); response.UploadedItemsCount = res.ValidationResults.Count(n => n.IsValid); return response; }
public HttpResponseMessage ImportMasterData(IEnumerable<ImportEntity> importData) { var response=new MasterDataValidationAndImportResponse(); try { var task=Task.Run(async () => { var res = await _integrationService.ImportMasterData(importData); response = GenerateResponse(res); }); Task.WaitAll(task); response.Result = "Success"; return Request.CreateResponse(HttpStatusCode.OK,response); } catch (Exception ex) //any other { response.Result = "Error"; response.ErrorInfo = "Error: An error occurred executing the task..see validation results for details.=>"+ex.Message; _log.Error("Error: An error occurred when importing masterdata:=>", ex); } return Request.CreateResponse(HttpStatusCode.OK, response); }