public async Task <IHttpActionResult> Upload() { var uploadResult = await _fileUploader.TryUploadFilesAsync(Request.Content, HttpContext.Current); if (!uploadResult.IsSuccessful) { return(BadRequest("File uploading error")); } var parseResults = await _textFileParser.ProcessUploadedFilesAsync(uploadResult); var successfulOperations = parseResults.SelectMany(x => x.SuccessfulOperations).ToList(); var unsuccessfulOperations = parseResults.SelectMany(x => x.UnsuccessfulOperations); var stations = successfulOperations.Select(x => ((StationParsingResult)x).Entity); // ONLY STATIONS WITH UNIQUE NAMES ARE ADDED! var addedCount = _metroStationStorage.AddRange(stations); var response = new { successfulOperationsCount = successfulOperations.Count, unsuccessfulOperationsCount = unsuccessfulOperations.Count(), addedCount = addedCount }; return(Ok(response)); }