コード例 #1
0
ファイル: ViewProduct.cs プロジェクト: csjwhat/CSharpASPStudy
        }     // end sub

        /// <summary>
        /// Model(M) Product のプロパティの値を元に、View Model(VM) Product の新しいインスタンスを初期化して返します。
        /// </summary>
        /// <param name="from">Model(M) Product のインスタンスを指定します。</param>
        /// <returns>新しい View Model(VM) Product のインスタンスを返します。</returns>
        public static ViewProduct FromProduct(BasicSpa.data.Products from)
        {
            var to = new ViewProduct();

            ViewProduct.SetProperties(from, to);
            return(to);
        } // end function
コード例 #2
0
ファイル: ViewProduct.cs プロジェクト: csjwhat/CSharpASPStudy
        } // end sub

        /// <summary>
        /// Model(M) Product のプロパティの値を、View Model(VM) Product のプロパティにコピーします。
        /// </summary>
        /// <param name="from">Model(M) Product のインスタンスを指定します。</param>
        /// <param name="to">View Model(VM) Product のインスタンスを指定します。</param>
        public static void SetProperties(BasicSpa.data.Products from, ViewProduct to)
        {
            to.Id           = from.Id;
            to.Title        = from.Title;
            to.ProductUrl   = from.ProductUrl;
            to.DownloadUrl  = from.DownloadUrl;
            to.Description  = from.Description_;
            to.Publisher    = from.Publisher;
            to.PublisherUrl = from.PublisherUrl;
            to.ImageUrl     = from.ImageUrl;

            if (from.Price.HasValue && from.Price.Value <= 0)
            {
                to.Price = "FREE";
            }
            else
            {
                to.Price = from.Price?.ToString("C") ?? "FREE";
            } // end if
        }     // end sub
コード例 #3
0
ファイル: ViewProduct.cs プロジェクト: csjwhat/CSharpASPStudy
        /// <summary>
        /// View Model(VM) Product のプロパティの値を、Model(M) Product のプロパティにコピーします。
        /// </summary>
        /// <param name="from">View Model(VM) Product のインスタンスを指定します。</param>
        /// <param name="to">Model(M) Product のインスタンスを指定します。</param>
        public static void SetProperties(ViewProduct from, BasicSpa.data.Products to)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            to.Id           = from.Id;
            to.Title        = from.Title?.Trim();
            to.ProductUrl   = from.ProductUrl?.Trim();
            to.DownloadUrl  = from.DownloadUrl?.Trim();
            to.Description_ = from.Description?.Trim();
            to.Publisher    = from.Publisher?.Trim();
            to.PublisherUrl = from.PublisherUrl?.Trim();
            to.ImageUrl     = from.ImageUrl?.Trim();

            Func <string, decimal?> toDecimal = text =>
            {
                if (string.IsNullOrWhiteSpace(text))
                {
                    return(null);
                }
                if (text == "FREE")
                {
                    return(0);
                }
                if (text == "無料")
                {
                    return(0);
                }

                return(Convert.ToDecimal(text.Replace(",", "")));
            };

            to.Price = toDecimal(from.Price?.Trim());
        } // end sub