Browse Source

Introduce CreateEditCategoryViewModel

pull/107/head 1.3.1
gdlcf88 6 years ago
parent
commit
8eb86ab901
  1. 2
      common.props
  2. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Categories/Category/CreateModal.cshtml.cs
  3. 9
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Categories/Category/EditModal.cshtml.cs
  4. 20
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Categories/Category/ViewModels/CreateEditProductViewModel.cs
  5. 5
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/ProductsWebAutoMapperProfile.cs

2
common.props

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>1.3.0</Version>
<Version>1.3.1</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>

7
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Categories/Category/CreateModal.cshtml.cs

@ -1,6 +1,7 @@
using System.Threading.Tasks;
using EasyAbp.EShop.Products.Categories;
using EasyAbp.EShop.Products.Categories.Dtos;
using EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category
@ -8,7 +9,7 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category
public class CreateModalModel : ProductsPageModel
{
[BindProperty]
public CreateUpdateCategoryDto Category { get; set; }
public CreateEditCategoryViewModel Category { get; set; }
private readonly ICategoryAppService _service;
@ -19,7 +20,9 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category
public async Task<IActionResult> OnPostAsync()
{
await _service.CreateAsync(Category);
await _service.CreateAsync(
ObjectMapper.Map<CreateEditCategoryViewModel, CreateUpdateCategoryDto>(Category));
return NoContent();
}
}

9
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Categories/Category/EditModal.cshtml.cs

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EasyAbp.EShop.Products.Categories;
using EasyAbp.EShop.Products.Categories.Dtos;
using EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category.ViewModels;
namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category
{
@ -13,7 +14,7 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category
public Guid Id { get; set; }
[BindProperty]
public CreateUpdateCategoryDto Category { get; set; }
public CreateEditCategoryViewModel Category { get; set; }
private readonly ICategoryAppService _service;
@ -25,12 +26,14 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category
public async Task OnGetAsync()
{
var dto = await _service.GetAsync(Id);
Category = ObjectMapper.Map<CategoryDto, CreateUpdateCategoryDto>(dto);
Category = ObjectMapper.Map<CategoryDto, CreateEditCategoryViewModel>(dto);
}
public async Task<IActionResult> OnPostAsync()
{
await _service.UpdateAsync(Id, Category);
await _service.UpdateAsync(Id,
ObjectMapper.Map<CreateEditCategoryViewModel, CreateUpdateCategoryDto>(Category));
return NoContent();
}
}

20
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Categories/Category/ViewModels/CreateEditProductViewModel.cs

@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category.ViewModels
{
public class CreateEditCategoryViewModel
{
[Display(Name = "CategoryUniqueName")]
public string UniqueName { get; set; }
[Required]
[Display(Name = "CategoryDisplayName")]
public string DisplayName { get; set; }
[Display(Name = "CategoryDescription")]
public string Description { get; set; }
[Display(Name = "CategoryMediaResources")]
public string MediaResources { get; set; }
}
}

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

@ -5,6 +5,7 @@ using EasyAbp.EShop.Products.Products.Dtos;
using EasyAbp.EShop.Products.Categories.Dtos;
using AutoMapper;
using EasyAbp.EShop.Products.ProductDetails.Dtos;
using EasyAbp.EShop.Products.Web.Pages.EShop.Products.Categories.Category.ViewModels;
using EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product.ViewModels;
using EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku.ViewModels;
using Volo.Abp.AutoMapper;
@ -68,7 +69,9 @@ namespace EasyAbp.EShop.Products.Web
CreateMap<ProductAttributeOptionDto, CreateEditProductAttributeOptionViewModel>();
CreateMap<CreateEditProductAttributeOptionViewModel, CreateUpdateProductAttributeOptionDto>()
.Ignore(dto => dto.ExtraProperties);
CreateMap<CategoryDto, CreateUpdateCategoryDto>();
CreateMap<CategoryDto, CreateEditCategoryViewModel>(MemberList.Destination);
CreateMap<CreateEditCategoryViewModel, CreateUpdateCategoryDto>()
.Ignore(dto => dto.ExtraProperties);
}
}
}

Loading…
Cancel
Save