private void SetBarcode(ProductEntity entity, bool needUpdate = true) { if (string.IsNullOrEmpty(entity.Barcode) || string.IsNullOrEmpty(entity.BarcodeUrl)) { var key = IdentityCreatorService.New(IdentityKey.PRODUCT_BARCODE); var barcode = key.ToString().PadLeft(13, '0'); var barcodeUrl = BarcodeHelper.CreateImg(barcode); entity.Barcode = barcode; entity.BarcodeUrl = barcodeUrl; if (needUpdate) { ProductRepository.UpdateBarcode(entity.Id, barcode, barcodeUrl); } } }