Esempio n. 1
0
 public static List<CategoryProduct> CreateModel(CategoryProductViewModel categoryViewModel)
 {
     List<CategoryProduct> categoryProds = new List<CategoryProduct>();
     foreach (int prodid in categoryViewModel.ProductsIds)
     {
         categoryProds.Add(new CategoryProduct()
         {
             IdCategory = categoryViewModel.CategoryId,
             IdProduct = prodid,
             Active = true
         });
     }
     return categoryProds;
 }
        public IHttpActionResult  PostCategoryAssignProducts(CategoryProductViewModel categoryAssignProductViewModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                //    catalogRepository.Insert(catalog);
                //    int catalogid = catalog.CatalogId;
                CategoryProductRepository categoryProdRepo = new CategoryProductRepository(new MyRoomDbContext());
                List<CategoryProduct> categoryProds = CategoryProductMapper.CreateModel(categoryAssignProductViewModel);
                if (categoryProds.Count>0)
                     categoryProdRepo.InsertCategoryProduct(categoryProds);
                else
                    categoryProdRepo.DeleteCategoryProduct(categoryAssignProductViewModel.CategoryId);
                 
                //    this.CreateStructureDirectories(catalogid);
                return Ok("The products has been assigned to category");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }