public async Task <IActionResult> CreatePackages(CreatePackageParameters parameters) { if (!parameters.Packages.Any()) { return(BadRequest()); } var packagesToCreate = parameters.Packages .Select(p => Package.CreateNew( size: p.Size, weight: p.Weight, isFragile: p.IsFragile, valueToPay: p.ValueToPay, countryCode: p.CountryCode, countryISOCode: GetCountryCodeDetails(p.CountryCode), areaCode: p.AreaCode, shipment: Shipment.CreateNew( checkPoint: CheckPoint.CreateNew( city: p.CheckPointDetails.City, country: p.CheckPointDetails.Country, controlType: p.CheckPointDetails.ControlType, placeType: p.CheckPointDetails.PlaceType)))); await _packageRepository.CreatePackages(packagesToCreate); return(Ok()); }
public async Task <IActionResult> CreatePackagesFromExcel(IFormFile file) { var path = Path.Combine(Path.GetTempPath(), file.FileName); using (var stream = System.IO.File.Create(path)) { await file.CopyToAsync(stream); } DataTable dataTable = null; using (Stream inputStream = System.IO.File.OpenRead(path)) { using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; IWorkbook workbook = application.Workbooks.Open(inputStream); IWorksheet worksheet = workbook.Worksheets[0]; dataTable = worksheet.ExportDataTable( worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames); } } List <Package> packagesToCreate = new List <Package>(); for (var i = 0; i < dataTable.Rows.Count; i++) { packagesToCreate.Add( Package.CreateNew( size: (PackageSize)Convert.ToInt32(dataTable.Rows[i]["Package_Size"]), weight: Convert.ToInt32(dataTable.Rows[i]["Package_Weight"]), isFragile: Convert.ToBoolean(dataTable.Rows[i]["Package_IsFragile"]), valueToPay: Convert.ToDecimal(dataTable.Rows[i]["Package_ValueToPay"]), countryCode: dataTable.Rows[i]["Package_CountryCode"].ToString(), countryISOCode: GetCountryCodeDetails(dataTable.Rows[i]["Package_CountryCode"].ToString()), areaCode: dataTable.Rows[i]["Package_AreaCode"].ToString(), shipment: Shipment.CreateNew( checkPoint: CheckPoint.CreateNew( city: dataTable.Rows[i]["CheckPoint_City"].ToString(), country: dataTable.Rows[i]["CheckPoint_Country"].ToString(), controlType: (ControlType)Convert.ToInt32(dataTable.Rows[i]["CheckPoint_ControlType"]), placeType: (PlaceType)Convert.ToInt32(dataTable.Rows[i]["CheckPoint_PlaceType"]))))); } await _packageRepository.CreatePackages(packagesToCreate); return(Ok()); }
public void Package_CreateNew_ShouldReturnANewPackage() { //Arrange var packageSize = PackageSize.S; var weight = 100; var isFragile = false; decimal valueToPay = 200; var countryCode = "PT"; var countryISOCode = 620; var areaCode = "Lis"; var country = "Portugal"; var city = "Lisbon"; var controlType = ControlType.Custom; var placeType = PlaceType.CustomsFacility; //Act var package = Package.CreateNew( size: packageSize, weight: weight, isFragile: isFragile, valueToPay: valueToPay, countryCode: countryCode, countryISOCode: countryISOCode, areaCode: areaCode, shipment: Shipment.CreateNew( CheckPoint.CreateNew( city: city, country: country, controlType: controlType, placeType: placeType))); //Assert Assert.AreNotEqual(Guid.Empty, package.PackageId); Assert.AreEqual(packageSize, package.Size); Assert.AreEqual(weight, package.Weight); Assert.AreEqual(isFragile, package.IsFragile); Assert.AreEqual(valueToPay, package.ValueToPay); Assert.IsTrue(!string.IsNullOrEmpty(package.TrackingCode)); Assert.AreEqual(country, package.Shipment.CheckPoint.Country); Assert.AreEqual(city, package.Shipment.CheckPoint.City); Assert.AreEqual(controlType, package.Shipment.CheckPoint.ControlType); Assert.AreEqual(placeType, package.Shipment.CheckPoint.PlaceType); }
public void CheckPoint_CreateNew_ShouldReturnANewCheckPoint() { //Arrange var country = "Portugal"; var city = "Lisbon"; var controlType = ControlType.Custom; var placeType = PlaceType.CustomsFacility; //Act var checkPoint = CheckPoint.CreateNew( city: city, country: country, controlType: controlType, placeType: placeType); //Assert Assert.AreNotEqual(Guid.Empty, checkPoint.CheckPointId); Assert.AreEqual(country, checkPoint.Country); Assert.AreEqual(city, checkPoint.City); Assert.AreEqual(controlType, checkPoint.ControlType); Assert.AreEqual(placeType, checkPoint.PlaceType); }