0

簡単な e コマース アプリケーションを作成しようとしています。商品にはブランドと少なくとも 1 つのカテゴリが必要です。私は Sharp Lite の例である MyStore と CaTs を (かなり頻繁に) 使用してきました。ProductController で Create アクションを作成しようとしています。

1) ProductController に、製品リポジトリと製品サービスの両方を挿入します。

2) Create アクションで、productService.CreateProductViewModel() を呼び出します。

3) CreateProductViewModel で、ViewModel が必要とするすべてのプロパティ (名前、製品コードなど) と、カテゴリとブランドの両方の IEnumerables を持つ新しい ProductFormDto を作成します。

    public CreateProductViewModel()
    {
        ProductFormDto = new ProductFormDto();
    }

    public ProductFormDto ProductFormDto { get; set; }
    public IEnumerable<ProductCategory> Categories { get; set; }
    public IEnumerable<Brand> Brands { get; set; }

}

かなり複雑なビューになると思います。

私の質問は、Sharp Lite を使用して、automapper を使用して ViewModel を次のようにマップする必要があるかどうかです。

    public void Map()
    {
        Mapper.CreateMap<Product, ProductFormDto>();
    }

これをタスク (サービス) レイヤーに ServiceLayerMappings.cs として配置しました。

もしそうなら、私が見た追加のマッピング コードをどこに配置しますか?ほとんどの例ではコントローラーに配置されていますか?

この ServiceLayerMappings を最初に呼び出す方法/場所/時期は?

ServiceLayerMappings は、Tasks レイヤーのルートにある 1 つのファイルにすべての ViewModel へのすべてのマップを持っていますか?

この時点で少し頭を悩ませているので、どんな種類のガイダンスも大歓迎です!

4

1 に答える 1

0

あ、持ってると思います。MyStore の例には CudTasks ファイルがあり、次のメソッドはその一部です。

    /// <summary>
    /// Udpates an entitry from the DB with new information from the form.  This example 
    /// manually copies the data but you could use a more sophisticated mechanism, like AutoMapper
    /// </summary>
    protected override void TransferFormValuesTo(ProductCategory toUpdate, ProductCategory fromForm) {
        toUpdate.Name = fromForm.Name;
        toUpdate.Parent = fromForm.Parent;
    }
于 2012-08-09T10:51:56.770 に答える