diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml b/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml index 4165781b58..9e32a2acad 100644 --- a/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml +++ b/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml @@ -8,6 +8,10 @@ @foreach (var product in Model.Products.Items) {
  • + @if (!product.ImageName.IsNullOrEmpty()) + { + + } @product.Code / @product.Name / $@product.Price
    Stock count: @product.StockCount
  • diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSite.Host.csproj b/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSite.Host.csproj index 158e41f576..b97bc35b68 100644 --- a/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSite.Host.csproj +++ b/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSite.Host.csproj @@ -39,6 +39,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/asus.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/asus.jpg new file mode 100644 index 0000000000..44de167813 Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/asus.jpg differ diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/beats.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/beats.jpg new file mode 100644 index 0000000000..08417c235b Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/beats.jpg differ diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/bluecat.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/bluecat.jpg new file mode 100644 index 0000000000..794a734a4a Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/bluecat.jpg differ diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/lego.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/lego.jpg new file mode 100644 index 0000000000..63e31e9577 Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/lego.jpg differ diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/nikon.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/nikon.jpg new file mode 100644 index 0000000000..eb6fb605a1 Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/nikon.jpg differ diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/oki.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/oki.jpg new file mode 100644 index 0000000000..6fefeec6e3 Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/oki.jpg differ diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/playstation.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/playstation.jpg new file mode 100644 index 0000000000..880832401a Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/playstation.jpg differ diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/rampage.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/rampage.jpg new file mode 100644 index 0000000000..e49660df17 Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/rampage.jpg differ diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/sunny.jpg b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/sunny.jpg new file mode 100644 index 0000000000..8efff5a674 Binary files /dev/null and b/samples/MicroserviceDemo/applications/PublicWebSite.Host/wwwroot/product-images/sunny.jpg differ diff --git a/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/20190307065413_Added_ImageName_To_Product.Designer.cs b/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/20190307065413_Added_ImageName_To_Product.Designer.cs new file mode 100644 index 0000000000..7106d08d50 --- /dev/null +++ b/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/20190307065413_Added_ImageName_To_Product.Designer.cs @@ -0,0 +1,74 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ProductService.Host.EntityFrameworkCore; + +namespace ProductService.Host.Migrations +{ + [DbContext(typeof(ProductServiceMigrationDbContext))] + [Migration("20190307065413_Added_ImageName_To_Product")] + partial class Added_ImageName_To_Product + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("ProductManagement.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Code") + .IsRequired() + .HasMaxLength(32); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnName("CreatorId"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("ImageName") + .HasMaxLength(128); + + b.Property("LastModificationTime") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnName("LastModifierId"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256); + + b.Property("Price"); + + b.Property("StockCount"); + + b.HasKey("Id"); + + b.HasIndex("Code"); + + b.HasIndex("Name"); + + b.ToTable("PmProducts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/20190307065413_Added_ImageName_To_Product.cs b/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/20190307065413_Added_ImageName_To_Product.cs new file mode 100644 index 0000000000..082bf9bf52 --- /dev/null +++ b/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/20190307065413_Added_ImageName_To_Product.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace ProductService.Host.Migrations +{ + public partial class Added_ImageName_To_Product : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImageName", + table: "PmProducts", + maxLength: 128, + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ImageName", + table: "PmProducts"); + } + } +} diff --git a/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/ProductServiceMigrationDbContextModelSnapshot.cs b/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/ProductServiceMigrationDbContextModelSnapshot.cs index 5bc9669fb0..dcbec3288c 100644 --- a/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/ProductServiceMigrationDbContextModelSnapshot.cs +++ b/samples/MicroserviceDemo/microservices/ProductService.Host/Migrations/ProductServiceMigrationDbContextModelSnapshot.cs @@ -41,6 +41,9 @@ namespace ProductService.Host.Migrations b.Property("ExtraProperties") .HasColumnName("ExtraProperties"); + b.Property("ImageName") + .HasMaxLength(128); + b.Property("LastModificationTime") .HasColumnName("LastModificationTime"); diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/CreateProductDto.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/CreateProductDto.cs index 693dd0d501..42091eb6ec 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/CreateProductDto.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/CreateProductDto.cs @@ -1,11 +1,20 @@ -namespace ProductManagement +using System.ComponentModel.DataAnnotations; + +namespace ProductManagement { public class CreateProductDto { + [Required] + [StringLength(ProductConsts.MaxCodeLength)] public string Code { get; set; } + [Required] + [StringLength(ProductConsts.MaxNameLength)] public string Name { get; set; } + [StringLength(ProductConsts.MaxImageNameLength)] + public string ImageName { get; set; } + public float Price { get; set; } public int StockCount { get; set; } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductDto.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductDto.cs index 86a4536785..959473001c 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductDto.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductDto.cs @@ -9,6 +9,8 @@ namespace ProductManagement public string Name { get; set; } + public string ImageName { get; set; } + public float Price { get; set; } public int StockCount { get; set; } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/UpdateProductDto.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/UpdateProductDto.cs index aa96bf9c51..744d58dbbe 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/UpdateProductDto.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/UpdateProductDto.cs @@ -1,9 +1,16 @@ -namespace ProductManagement +using System.ComponentModel.DataAnnotations; + +namespace ProductManagement { public class UpdateProductDto { + [Required] + [StringLength(ProductConsts.MaxNameLength)] public string Name { get; set; } + [StringLength(ProductConsts.MaxImageNameLength)] + public string ImageName { get; set; } + public float Price { get; set; } public int StockCount { get; set; } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs index c993f27f02..25a596b24e 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs @@ -59,7 +59,13 @@ namespace ProductManagement [Authorize(ProductManagementPermissions.Products.Create)] public async Task CreateAsync(CreateProductDto input) { - var product = await _productManager.CreateAsync(input.Code, input.Name, input.Price, input.StockCount); + var product = await _productManager.CreateAsync( + input.Code, + input.Name, + input.Price, + input.StockCount, + input.ImageName + ); return ObjectMapper.Map(product); } @@ -72,6 +78,7 @@ namespace ProductManagement product.SetName(input.Name); product.SetPrice(input.Price); product.SetStockCount(input.StockCount); + product.SetImageName(input.ImageName); return ObjectMapper.Map(product); } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain.Shared/ProductManagement/ProductConsts.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain.Shared/ProductManagement/ProductConsts.cs index c6cc028936..26ca7ccea5 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain.Shared/ProductManagement/ProductConsts.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain.Shared/ProductManagement/ProductConsts.cs @@ -5,5 +5,7 @@ public const int MaxCodeLength = 32; public const int MaxNameLength = 256; + + public const int MaxImageNameLength = 128; } } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/Product.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/Product.cs index bca0a7b09d..6686637185 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/Product.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/Product.cs @@ -22,6 +22,8 @@ namespace ProductManagement public int StockCount { get; private set; } + public string ImageName { get; private set; } + private Product() { //Default constructor is needed for ORMs. @@ -32,7 +34,8 @@ namespace ProductManagement [NotNull] string code, [NotNull] string name, float price = 0.0f, - int stockCount = 0) + int stockCount = 0, + string imageName = null) { Check.NotNullOrWhiteSpace(code, nameof(code)); @@ -45,6 +48,7 @@ namespace ProductManagement Code = code; SetName(Check.NotNullOrWhiteSpace(name, nameof(name))); SetPrice(price); + SetImageName(imageName); SetStockCountInternal(stockCount, triggerEvent: false); } @@ -61,6 +65,22 @@ namespace ProductManagement return this; } + public Product SetImageName([CanBeNull] string imageName) + { + if (imageName == null) + { + return this; + } + + if (imageName.Length >= ProductConsts.MaxImageNameLength) + { + throw new ArgumentException($"Product image name can not be longer than {ProductConsts.MaxImageNameLength}"); + } + + ImageName = imageName; + return this; + } + public Product SetPrice(float price) { if (price < 0.0f) diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/ProductManager.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/ProductManager.cs index 4c39feb7bf..9b924ca1d6 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/ProductManager.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/ProductManager.cs @@ -20,7 +20,8 @@ namespace ProductManagement [NotNull] string code, [NotNull] string name, float price = 0.0f, - int stockCount = 0) + int stockCount = 0, + string imageName = null) { var existingProduct = await _productRepository.FirstOrDefaultAsync(p => p.Code == code); if (existingProduct != null) @@ -34,7 +35,8 @@ namespace ProductManagement code, name, price, - stockCount + stockCount, + imageName ) ); } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement/EntityFrameworkCore/ProductManagementDbContextModelCreatingExtensions.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement/EntityFrameworkCore/ProductManagementDbContextModelCreatingExtensions.cs index 8a12ad11a8..94d74e836f 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement/EntityFrameworkCore/ProductManagementDbContextModelCreatingExtensions.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement/EntityFrameworkCore/ProductManagementDbContextModelCreatingExtensions.cs @@ -27,6 +27,7 @@ namespace ProductManagement.EntityFrameworkCore b.Property(x => x.Code).IsRequired().HasMaxLength(ProductConsts.MaxCodeLength); b.Property(x => x.Name).IsRequired().HasMaxLength(ProductConsts.MaxNameLength); + b.Property(x => x.ImageName).HasMaxLength(ProductConsts.MaxImageNameLength); b.HasIndex(q => q.Code); b.HasIndex(q => q.Name); diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Localization/Resources/ProductManagement/en.json b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Localization/Resources/ProductManagement/en.json index d9e9ea167a..39d48b30e2 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Localization/Resources/ProductManagement/en.json +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Localization/Resources/ProductManagement/en.json @@ -10,6 +10,7 @@ "Code": "Code", "Name": "Name", "Price": "Price", + "ImageName": "Image Name", "ProductDeletionWarningMessage": "Are you sure you want to delete this product?" } } \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Pages/ProductManagement/Products/Create.cshtml.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Pages/ProductManagement/Products/Create.cshtml.cs index 89188ad2d2..e660ff8f8b 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Pages/ProductManagement/Products/Create.cshtml.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Pages/ProductManagement/Products/Create.cshtml.cs @@ -10,7 +10,7 @@ namespace ProductManagement.Pages.ProductManagement.Products private readonly IProductAppService _productAppService; [BindProperty] - public ProductCreateModalView Product { get; set; } = new ProductCreateModalView(); + public ProductCreateViewModel Product { get; set; } = new ProductCreateViewModel(); public CreateModel(IProductAppService productAppService) { @@ -19,14 +19,14 @@ namespace ProductManagement.Pages.ProductManagement.Products public async Task OnPostAsync() { - var createProductDto = ObjectMapper.Map(Product); + var createProductDto = ObjectMapper.Map(Product); await _productAppService.CreateAsync(createProductDto); return NoContent(); } - public class ProductCreateModalView + public class ProductCreateViewModel { [Required] [StringLength(ProductConsts.MaxCodeLength)] @@ -36,6 +36,9 @@ namespace ProductManagement.Pages.ProductManagement.Products [StringLength(ProductConsts.MaxNameLength)] public string Name { get; set; } + [StringLength(ProductConsts.MaxImageNameLength)] + public string ImageName { get; set; } + public float Price { get; set; } public int StockCount { get; set; } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Pages/ProductManagement/Products/Edit.cshtml.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Pages/ProductManagement/Products/Edit.cshtml.cs index 4776f135bd..d0b2450e97 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Pages/ProductManagement/Products/Edit.cshtml.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/Pages/ProductManagement/Products/Edit.cshtml.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; namespace ProductManagement.Pages.ProductManagement.Products @@ -14,7 +11,7 @@ namespace ProductManagement.Pages.ProductManagement.Products private readonly IProductAppService _productAppService; [BindProperty] - public ProductEditModalView Product { get; set; } = new ProductEditModalView(); + public ProductEditViewModel Product { get; set; } = new ProductEditViewModel(); public EditModel(IProductAppService productAppService) { @@ -25,7 +22,7 @@ namespace ProductManagement.Pages.ProductManagement.Products { var productDto = await _productAppService.GetAsync(productId); - Product = ObjectMapper.Map(productDto); + Product = ObjectMapper.Map(productDto); return Page(); } @@ -40,7 +37,7 @@ namespace ProductManagement.Pages.ProductManagement.Products }); } - public class ProductEditModalView + public class ProductEditViewModel { [HiddenInput] [Required] @@ -50,6 +47,9 @@ namespace ProductManagement.Pages.ProductManagement.Products [StringLength(ProductConsts.MaxNameLength)] public string Name { get; set; } + [StringLength(ProductConsts.MaxImageNameLength)] + public string ImageName { get; set; } + public float Price { get; set; } public int StockCount { get; set; } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/ProductManagementWebAutoMapperProfile.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/ProductManagementWebAutoMapperProfile.cs index 43b2be406a..577aa0f352 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/ProductManagementWebAutoMapperProfile.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/ProductManagementWebAutoMapperProfile.cs @@ -7,8 +7,8 @@ namespace ProductManagement { public ProductManagementWebAutoMapperProfile() { - CreateMap(); - CreateMap(); + CreateMap(); + CreateMap(); } } } \ No newline at end of file