Example #1
0
        public static ProductViewModel ToProductViewModel(this Product prod)
        {
            if (prod == null)
            {
                return(null);
            }
            Areas.Admin.Models.ProductViewModel product = new Areas.Admin.Models.ProductViewModel()
            {
                ProductID        = prod.Id,
                Name             = prod.Name,
                ShortDescription = prod.Description,
                LongDescription  = prod.LongDescription,
                IsActive         = prod.IsActive,
                Price            = prod.Price,
                //SubCategoryName = prod.SubCategory.Name,
                SubSelectedId = prod.SubCategoryId.Value,
                Path          = prod.Images
            };
            if (product.Path != null)
            {
                char[]   delim = { ',' };
                string[] res   = product.Path.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                product.Images = new List <string>(res.ToList());
            }

            return(product);
        }
Example #2
0
        public static Product ToProduct(this Areas.Admin.Models.ProductViewModel pm)
        {
            if (pm == null)
            {
                return(null);
            }
            var product = new Product()
            {
                Id              = pm.ProductID,
                Name            = pm.Name,
                IsActive        = pm.IsActive,
                Description     = pm.ShortDescription,
                Price           = pm.Price,
                LongDescription = pm.LongDescription,
                SubCategoryId   = pm.SubSelectedId,
                Images          = pm.Path
            };

            //if(pm.Path != null)
            //{
            //    char[] delim = { ',' };
            //    string[] res = pm.Path.Split(delim,StringSplitOptions.RemoveEmptyEntries);
            //    product.Images = new List<string>();
            //    product.Images.AddRange(res);
            //}
            //if(pm.Images != null)
            //{
            //    product.Images = pm.Images;
            //}
            return(product);
        }