Added Image to products

pull/870/head
Halil ibrahim Kalkan 7 years ago
parent 1275f2207f
commit ac69dc0a0a

@ -8,6 +8,10 @@
@foreach (var product in Model.Products.Items)
{
<li>
@if (!product.ImageName.IsNullOrEmpty())
{
<img src="/product-images/@product.ImageName" width="300" height="300"/>
}
@product.Code / @product.Name / $@product.Price <br/>
<i>Stock count: @product.StockCount</i>
</li>

@ -39,6 +39,30 @@
<None Remove="Logs\**" />
</ItemGroup>
<ItemGroup>
<Content Remove="wwwroot\product-images\asus.jpg" />
<Content Remove="wwwroot\product-images\beats.jpg" />
<Content Remove="wwwroot\product-images\bluecat.jpg" />
<Content Remove="wwwroot\product-images\lego.jpg" />
<Content Remove="wwwroot\product-images\nikon.jpg" />
<Content Remove="wwwroot\product-images\oki.jpg" />
<Content Remove="wwwroot\product-images\playstation.jpg" />
<Content Remove="wwwroot\product-images\rampage.jpg" />
<Content Remove="wwwroot\product-images\sunny.jpg" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="wwwroot\product-images\asus.jpg" />
<EmbeddedResource Include="wwwroot\product-images\beats.jpg" />
<EmbeddedResource Include="wwwroot\product-images\bluecat.jpg" />
<EmbeddedResource Include="wwwroot\product-images\lego.jpg" />
<EmbeddedResource Include="wwwroot\product-images\nikon.jpg" />
<EmbeddedResource Include="wwwroot\product-images\oki.jpg" />
<EmbeddedResource Include="wwwroot\product-images\playstation.jpg" />
<EmbeddedResource Include="wwwroot\product-images\rampage.jpg" />
<EmbeddedResource Include="wwwroot\product-images\sunny.jpg" />
</ItemGroup>
<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'StackExchange.Redis.StrongName'">

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

@ -0,0 +1,74 @@
// <auto-generated />
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<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(32);
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId");
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties");
b.Property<string>("ImageName")
.HasMaxLength(128);
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(256);
b.Property<float>("Price");
b.Property<int>("StockCount");
b.HasKey("Id");
b.HasIndex("Code");
b.HasIndex("Name");
b.ToTable("PmProducts");
});
#pragma warning restore 612, 618
}
}
}

@ -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<string>(
name: "ImageName",
table: "PmProducts",
maxLength: 128,
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ImageName",
table: "PmProducts");
}
}
}

@ -41,6 +41,9 @@ namespace ProductService.Host.Migrations
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties");
b.Property<string>("ImageName")
.HasMaxLength(128);
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime");

@ -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; }

@ -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; }

@ -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; }

@ -59,7 +59,13 @@ namespace ProductManagement
[Authorize(ProductManagementPermissions.Products.Create)]
public async Task<ProductDto> 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, ProductDto>(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, ProductDto>(product);
}

@ -5,5 +5,7 @@
public const int MaxCodeLength = 32;
public const int MaxNameLength = 256;
public const int MaxImageNameLength = 128;
}
}

@ -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)

@ -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
)
);
}

@ -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);

@ -10,6 +10,7 @@
"Code": "Code",
"Name": "Name",
"Price": "Price",
"ImageName": "Image Name",
"ProductDeletionWarningMessage": "Are you sure you want to delete this product?"
}
}

@ -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<IActionResult> OnPostAsync()
{
var createProductDto = ObjectMapper.Map<ProductCreateModalView, CreateProductDto>(Product);
var createProductDto = ObjectMapper.Map<ProductCreateViewModel, CreateProductDto>(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; }

@ -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, ProductEditModalView>(productDto);
Product = ObjectMapper.Map<ProductDto, ProductEditViewModel>(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; }

@ -7,8 +7,8 @@ namespace ProductManagement
{
public ProductManagementWebAutoMapperProfile()
{
CreateMap<CreateModel.ProductCreateModalView, CreateProductDto>();
CreateMap<ProductDto, EditModel.ProductEditModalView>();
CreateMap<CreateModel.ProductCreateViewModel, CreateProductDto>();
CreateMap<ProductDto, EditModel.ProductEditViewModel>();
}
}
}
Loading…
Cancel
Save