Пример #1
0
        public List <ProductModel> GetByPartialName(string name)
        {
            var productModels = new List <ProductModel>();

            foreach (var product in _repository.GetByName().Where(x => x.Name.Contains(name)))
            {
                productModels.Add(ProductModelBuilder.Create(product));
            }
            return(productModels);
        }
Пример #2
0
        public List <ProductModel> GetAllProducts()
        {
            var productModelList = new List <ProductModel>();

            foreach (var p in _repository.GetAll())
            {
                productModelList.Add(ProductModelBuilder.Create(p));
            }

            return(productModelList);
        }
Пример #3
0
        public List <ProductModel> GetAllProductsByCategory(int id)
        {
            var productModelList = new List <ProductModel>();

            foreach (var prod in _repository.GetAll().Where(prod => prod.Category?.Id == id))
            {
                productModelList.Add(ProductModelBuilder.Create(prod));
            }

            return(productModelList);
        }
Пример #4
0
        public ProductModel CreateProduct(ProductModel productC)
        {
            Product newProduct = new Product
            {
                Name            = productC.name,
                Description     = productC.description,
                Price           = productC.price,
                PublicationDate = DateTime.Now
            };


            newProduct.Category = _context.Categories.Single(c => c.Id == productC.categoryId);

            return(ProductModelBuilder.Create(_repository.Add(newProduct)));
        }
Пример #5
0
        public ProductModel ModifyProduct(ProductModel productU)
        {
            if (_repository.GetById(productU.id) == null)
            {
                throw new ArgumentException("Le produit est introuvable.");
            }

            var productToUpdate = new Product
            {
                Id              = productU.id,
                Name            = productU.name,
                Price           = productU.price,
                PublicationDate = DateTime.Now,
                Description     = productU.description,
                Category        = new Category {
                    Id = productU.categoryId
                }
            };

            return(ProductModelBuilder.Create(_repository.Update(productToUpdate)));
        }
Пример #6
0
 public ProductModel GetProductByName(string name)
 {
     return(ProductModelBuilder.Create(_repository.GetSingle(x => x.Name == name)));
 }
Пример #7
0
 public ProductModel GetProductById(int id)
 {
     return(ProductModelBuilder.Create(_repository.GetById(id)));
 }