Exemple #1
0
        public bool Insert(ProductPanelInsertDTO dto)
        {
            bool result = false;

            var imagePath = ImageExtension.SaveTowwwroot(dto.Img, "Product");

            var pdlist = new List <ProductCategory>();

            if (dto.CategoryMultiSelectDTO.CategoryIds != null && dto.CategoryMultiSelectDTO.CategoryIds.Count > 0)
            {
                foreach (var categoryId in dto.CategoryMultiSelectDTO.CategoryIds)
                {
                    var pd = new ProductCategory
                    {
                        CategoryId = categoryId
                    };

                    pdlist.Add(pd);
                }
            }

            var pr = new Product()
            {
                Name            = dto.Name,
                Price           = dto.Price,
                Quantity        = dto.Quantity,
                ImagePath       = imagePath,
                ProductCategory = pdlist
            };

            int inserted = _repository.Insert(pr);

            if (inserted > 0)
            {
                result = true;
            }
            return(result);
        }