public async Task UpdateDataset(Guid id, DatasetToSaveDTO dataset) { await _repository.UpdateDatasetAsync(new Dataset { Id = id, Name = dataset.Name, Records = dataset.Records.Select(record => new Record { Inputs = record.Inputs, Output = record.Output }).ToArray() }); }
public async Task <IActionResult> UploadDataByDatasetIdAsync(long id, IFormFile file) { if (file == null) { return(BadRequest(ResponseResult.Failed(ErrorCode.ValidationError, "File can't be empty."))); } var dataset = await _datasetRepository.GetDatasetByIdAsync(id); if (dataset == null) { return(NotFound(ResponseResult.Failed(ErrorCode.Error, "Dataset isn't found."))); } if (dataset.IsImported) { return(BadRequest(ResponseResult.Failed(ErrorCode.Error, "Dataset can't be imported more than once."))); } var friendships = new List <Friendship>(); using (StreamReader streamReader = new StreamReader(file.OpenReadStream())) { string line; while ((line = streamReader.ReadLine()) != null) { var fields = line.Split(' '); friendships.Add(Friendship.New(long.Parse(fields[0]), long.Parse(fields[1]), dataset)); } } await _friendShipRepository.AddDataAsync(friendships); dataset.Update(); await _datasetRepository.UpdateDatasetAsync(dataset); return(Ok(ResponseResult.Succeeded())); }