Browse Source

Fix a product editing bug.

pull/116/head
gdlcf88 6 years ago
parent
commit
6b9752a88a
  1. 10
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml.cs
  2. 11
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/EditModal.cshtml.cs
  3. 6
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateEditProductDetailViewModel.cs
  4. 4
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateEditProductViewModel.cs
  5. 12
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/EditProductDetailViewModel.cs
  6. 58
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/EditProductViewModel.cs
  7. 27
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/ProductsWebAutoMapperProfile.cs

10
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml.cs

@ -18,7 +18,7 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product
public class CreateModalModel : ProductsPageModel
{
[BindProperty]
public CreateProductViewModel Product { get; set; }
public CreateEditProductViewModel Product { get; set; }
public ICollection<SelectListItem> ProductGroups { get; set; }
@ -49,10 +49,10 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product
{ MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount }))?.Items
.Select(dto => new SelectListItem(dto.DisplayName, dto.Id.ToString())).ToList();
Product = new CreateProductViewModel
Product = new CreateEditProductViewModel
{
StoreId = storeId,
ProductDetail = new CreateProductDetailViewModel
ProductDetail = new CreateEditProductDetailViewModel
{
StoreId = storeId
}
@ -68,9 +68,9 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product
{
var detail = await _productDetailAppService.CreateAsync(
ObjectMapper
.Map<CreateProductDetailViewModel, CreateUpdateProductDetailDto>(Product.ProductDetail));
.Map<CreateEditProductDetailViewModel, CreateUpdateProductDetailDto>(Product.ProductDetail));
var createDto = ObjectMapper.Map<CreateProductViewModel, CreateUpdateProductDto>(Product);
var createDto = ObjectMapper.Map<CreateEditProductViewModel, CreateUpdateProductDto>(Product);
createDto.ProductDetailId = detail.Id;

11
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/EditModal.cshtml.cs

@ -24,7 +24,7 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product
public Guid Id { get; set; }
[BindProperty]
public EditProductViewModel Product { get; set; }
public CreateEditProductViewModel Product { get; set; }
public ICollection<SelectListItem> ProductGroups { get; set; }
@ -62,7 +62,7 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product
var detailDto = await _productDetailAppService.GetAsync(productDto.ProductDetailId);
Product = ObjectMapper.Map<ProductDto, EditProductViewModel>(productDto);
Product = ObjectMapper.Map<ProductDto, CreateEditProductViewModel>(productDto);
Product.CategoryIds = (await _productCategoryAppService.GetListAsync(new GetProductCategoryListDto
{
@ -70,8 +70,9 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product
MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount
})).Items.Select(x => x.CategoryId).ToList();
Product.ProductDetail = new EditProductDetailViewModel
Product.ProductDetail = new CreateEditProductDetailViewModel
{
StoreId = detailDto.StoreId,
Description = detailDto.Description
};
}
@ -84,9 +85,9 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product
await _productDetailAppService.UpdateAsync(detail.Id,
ObjectMapper
.Map<EditProductDetailViewModel, CreateUpdateProductDetailDto>(Product.ProductDetail));
.Map<CreateEditProductDetailViewModel, CreateUpdateProductDetailDto>(Product.ProductDetail));
var updateProductDto = ObjectMapper.Map<EditProductViewModel, CreateUpdateProductDto>(Product);
var updateProductDto = ObjectMapper.Map<CreateEditProductViewModel, CreateUpdateProductDto>(Product);
updateProductDto.ProductDetailId = detail.Id;

6
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateProductDetailViewModel.cs → modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateEditProductDetailViewModel.cs

@ -9,10 +9,14 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form;
namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product.ViewModels
{
public class CreateProductDetailViewModel : EditProductDetailViewModel
public class CreateEditProductDetailViewModel
{
[HiddenInput]
[Display(Name = "ProductDetailStoreId")]
public Guid? StoreId { get; set; }
[TextArea(Rows = 4)]
[Display(Name = "ProductDetailDescription")]
public string Description { get; set; }
}
}

4
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateProductViewModel.cs → modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateEditProductViewModel.cs

@ -8,7 +8,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form;
namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product.ViewModels
{
public class CreateProductViewModel : IValidatableObject
public class CreateEditProductViewModel : IValidatableObject
{
[HiddenInput]
[Display(Name = "ProductStoreId")]
@ -35,7 +35,7 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product.ViewM
[Display(Name = "ProductDisplayName")]
public string DisplayName { get; set; }
public CreateProductDetailViewModel ProductDetail { get; set; }
public CreateEditProductDetailViewModel ProductDetail { get; set; }
[Required]
[Placeholder("ProductAttributeNamesPlaceholder")]

12
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/EditProductDetailViewModel.cs

@ -1,12 +0,0 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form;
namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product.ViewModels
{
public class EditProductDetailViewModel
{
[TextArea(Rows = 4)]
[Display(Name = "ProductDetailDescription")]
public string Description { get; set; }
}
}

58
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/EditProductViewModel.cs

@ -1,58 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using EasyAbp.Abp.TagHelperPlus.EasySelector;
using EasyAbp.EShop.Products.Products;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form;
namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product.ViewModels
{
public class EditProductViewModel
{
[Required]
[SelectItems("ProductGroups")]
[Display(Name = "ProductProductGroupName")]
public string ProductGroupName { get; set; }
// [SelectItems("Categories")]
[EasySelector(
getListedDataSourceUrl: ProductsConsts.GetCategorySummaryListedDataSourceUrl,
getSingleDataSourceUrl: ProductsConsts.GetCategorySummarySingleDataSourceUrl,
keyPropertyName: "id",
textPropertyName: "displayName")]
[Display(Name = "ProductCategory")]
public List<Guid> CategoryIds { get; set; }
[Display(Name = "ProductUniqueName")]
public string UniqueName { get; set; }
[Required]
[Display(Name = "ProductDisplayName")]
public string DisplayName { get; set; }
public EditProductDetailViewModel ProductDetail { get; set; }
[Required]
[Placeholder("ProductAttributeNamesPlaceholder")]
[Display(Name = "ProductAttributeNames")]
public string ProductAttributeNames { get; set; }
[Required]
[TextArea(Rows = 4)]
[Placeholder("ProductAttributeOptionNamesPlaceholder")]
[Display(Name = "ProductAttributeOptionNames")]
public string ProductAttributeOptionNames { get; set; }
[Display(Name = "ProductInventoryStrategy")]
public InventoryStrategy InventoryStrategy { get; set; }
[Display(Name = "ProductDisplayOrder")]
public int DisplayOrder { get; set; }
[Display(Name = "ProductMediaResources")]
public string MediaResources { get; set; }
[Display(Name = "ProductIsPublished")]
public bool IsPublished { get; set; }
}
}

27
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/ProductsWebAutoMapperProfile.cs

@ -19,7 +19,7 @@ namespace EasyAbp.EShop.Products.Web
/* You can configure your AutoMapper mapping configuration here.
* Alternatively, you can split your mapping configurations
* into multiple profile classes for a better organization. */
CreateMap<ProductDto, EditProductViewModel>()
CreateMap<ProductDto, CreateEditProductViewModel>()
.Ignore(model => model.CategoryIds)
.Ignore(model => model.ProductDetail)
.ForSourceMember(dto => dto.Sold, opt => opt.DoNotValidate())
@ -33,7 +33,7 @@ namespace EasyAbp.EShop.Products.Web
x.ProductAttributes
.Select(a => a.ProductAttributeOptions.Select(o => o.DisplayName).JoinAsString(","))
.JoinAsString(Environment.NewLine)));
CreateMap<CreateProductViewModel, CreateUpdateProductDto>()
CreateMap<CreateEditProductViewModel, CreateUpdateProductDto>()
.Ignore(dto => dto.ExtraProperties)
.Ignore(dto => dto.ProductDetailId)
.ForSourceMember(model => model.ProductDetail, opt => opt.DoNotValidate())
@ -48,27 +48,8 @@ namespace EasyAbp.EShop.Products.Web
.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(o =>
new CreateUpdateProductAttributeOptionDto {DisplayName = o}))
})));
CreateMap<EditProductViewModel, CreateUpdateProductDto>()
.Ignore(dto => dto.StoreId)
.Ignore(dto => dto.ExtraProperties)
.Ignore(dto => dto.ProductDetailId)
.ForSourceMember(model => model.ProductDetail, opt => opt.DoNotValidate())
.ForMember(dest => dest.ProductAttributes,
opt => opt.MapFrom(x =>
x.ProductAttributeNames.Split(",", StringSplitOptions.RemoveEmptyEntries).Select((s, i) =>
new CreateUpdateProductAttributeDto
{
DisplayName = s,
ProductAttributeOptions = new List<CreateUpdateProductAttributeOptionDto>(
x.ProductAttributeOptionNames.SplitToLines(StringSplitOptions.RemoveEmptyEntries)[i]
.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(o =>
new CreateUpdateProductAttributeOptionDto {DisplayName = o}))
})));
CreateMap<ProductDetailDto, CreateProductDetailViewModel>();
CreateMap<CreateProductDetailViewModel, CreateUpdateProductDetailDto>()
.Ignore(dto => dto.ExtraProperties);
CreateMap<EditProductDetailViewModel, CreateUpdateProductDetailDto>()
.Ignore(dto => dto.StoreId)
CreateMap<ProductDetailDto, CreateEditProductDetailViewModel>();
CreateMap<CreateEditProductDetailViewModel, CreateUpdateProductDetailDto>()
.Ignore(dto => dto.ExtraProperties);
CreateMap<ProductAttributeDto, CreateEditProductAttributeViewModel>();
CreateMap<CreateEditProductAttributeViewModel, CreateUpdateProductAttributeDto>()

Loading…
Cancel
Save