public async Task <List <MoveDetail> > CreateMove(MoveFileDTO file) { var listMoveDetail = new List <MoveDetail>(); Move move = new Move { IdMove = 0, DateMove = DateTime.Now, IdentificationCard = file.IdentificationCard }; using (var reader = new StreamReader(file.File.OpenReadStream())) { int index = 1; while (reader.Peek() >= 0) { var moveDetail = new MoveDetail { IdMove = move.IdMove, Value = Int32.Parse(reader.ReadLine()), Position = index }; listMoveDetail.Add(moveDetail); index++; } } move.MoveDetail = listMoveDetail; await Context.AddAsync(move); Context.SaveChanges(); return(listMoveDetail); }
public async Task <List <string> > CreateMove(MoveFileDTO file) { var moveDetails = await this.moveRepository.CreateMove(file); List <MoveDetailDTO> list = _mapperDependency.Map <List <MoveDetailDTO> >(moveDetails.ToList()); return(GetMovingGrips(list)); }
public async Task <List <string> > CreateMove(MoveFileDTO file) { MoveDTO moveDTO = new MoveDTO { IdMove = 0, DateMove = DateTime.Now, IdentificationCard = file.IdentificationCard }; moveDTO.MoveDetailDTO = new List <MoveDetailDTO>(); using (var reader = new StreamReader(file.File.OpenReadStream())) { int index = 1; while (reader.Peek() >= 0) { var moveDetailDTO = new MoveDetailDTO { IdMove = moveDTO.IdMove, Value = Int32.Parse(reader.ReadLine()), Position = index }; moveDTO.MoveDetailDTO.Add(moveDetailDTO); index++; } } if (!_moveValidate.Validate(moveDTO).IsValid) { string response = ""; foreach (var item in _moveValidate.Validate(moveDTO).Errors.ToList()) { response = response + "\n" + item; } throw new Exception(response); } List <string> listToReturn = GetMovingGrips(moveDTO.MoveDetailDTO); await this.moveRepository.CreateAsync(_mapperDependency.Map <Move>(moveDTO)); return(listToReturn); }
public async Task <IActionResult> UploadFiles([FromForm] MoveFileDTO file) { try { if (file.File == null || file.File.Length == 0) { return(Json(_configuration.GetConnectionString("EmptyFile").AsResponseDTO((int)HttpStatusCode.NoContent))); } var listToDownload = await this.moveService.CreateMove(file); return(Json(listToDownload.AsResponseDTO((int)HttpStatusCode.OK))); } catch (Exception ex) { RollbarLocator.RollbarInstance.Error(ex); return(Json(ResponseExtension.AsResponseDTO <string>(null, (int)HttpStatusCode.InternalServerError, ex.Message))); } }