public IEnumerable <LocalEnterprisePartnershipStagingDto> Parse(FileImportDto fileImportDto) { if (!(fileImportDto is LocalEnterprisePartnershipStagingFileImportDto data)) { return(null); } var localEnterprisePartnershipStagingDto = new LocalEnterprisePartnershipStagingDto { Code = data.Code, Name = data.Name, CreatedBy = data.CreatedBy }; return(new List <LocalEnterprisePartnershipStagingDto> { localEnterprisePartnershipStagingDto }); }
public IEnumerable <PostcodeLookupStagingDto> Parse(FileImportDto fileImportDto) { if (!(fileImportDto is PostcodeLookupStagingFileImportDto data)) { return(null); } var postcodeLookupStagingDto = new PostcodeLookupStagingDto { Postcode = data.Postcode, PrimaryLepCode = data.PrimaryLepCode, SecondaryLepCode = data.SecondaryLepCode, CreatedBy = data.CreatedBy }; return(new List <PostcodeLookupStagingDto> { postcodeLookupStagingDto }); }
public IEnumerable <LearningAimReferenceStagingDto> Parse(FileImportDto fileImportDto) { if (!(fileImportDto is LearningAimReferenceStagingFileImportDto data)) { return(null); } var learningAimReferenceStagingDto = new LearningAimReferenceStagingDto { LarId = data.LarId, Title = data.Title, AwardOrgLarId = data.AwardOrgLarId, SourceCreatedOn = data.SourceCreatedOn.ToDateTime(), SourceModifiedOn = data.SourceModifiedOn.ToDateTime(), CreatedBy = data.CreatedBy }; return(new List <LearningAimReferenceStagingDto> { learningAimReferenceStagingDto }); }
public async Task <Response> ImportFile(FileImportDto dto) { var response = new Response(); var lines = System.IO.File.ReadLines(dto.UploadedFileName); foreach (var line in lines.Skip(1)) //Skip Header { try { var splittedRow = line.Split(','); if (splittedRow.Length != 10) { response.Warnings.Add(string.Format(_errorHandler.GetMessage(ErrorMessages.InputRowColumnCountIsNotExpected), line)); } else { decimal price = 0, discount = 0; if (!decimal.TryParse(splittedRow[4], out price)) { response.Warnings.Add(string.Format(_errorHandler.GetMessage(ErrorMessages.WrongFormat), "Price", line)); } if (!decimal.TryParse(splittedRow[5], out discount)) { response.Warnings.Add(string.Format(_errorHandler.GetMessage(ErrorMessages.WrongFormat), "DiscountPrice", line)); } //Product var product = _productRepo.GetAll().FirstOrDefault(p => p.ArtikelCode == splittedRow[1] && p.ColorCode == splittedRow[2] && p.Description == splittedRow[3]); if (product == null) { product = await _productRepo.Add(new Product() { ArtikelCode = splittedRow[1], ColorCode = splittedRow[2], Description = splittedRow[3] }); } //Color var color = _colorRepo.GetAll().FirstOrDefault(p => p.Name == splittedRow[9]); if (color == null) { color = await _colorRepo.Add(new Color() { Name = splittedRow[9] }); } //Size var size = _sizeRepo.GetAll().FirstOrDefault(p => p.Name == splittedRow[8]); if (size == null) { size = await _sizeRepo.Add(new Size() { Name = splittedRow[8] }); } var productVar = new ProductVariation() { Key = splittedRow[0], Price = price, DiscountPrice = discount, DeliveredIn = splittedRow[6], Q1 = splittedRow[7], ColorId = color.Id, ProductId = product.Id, SizeId = size.Id, }; await _productVariationRepo.Add(productVar); } } catch (System.Exception ex) { response.HasError = true; response.Errors.Add(string.Format(_errorHandler.GetMessage(ErrorMessages.UnexpectedError), ex.Message, line)); } } return(response); }