public async Task <IActionResult> GetSubCategory(int id) { var sectionFroRepo = await _repo.GetSubCategory(id); var sections = _mapper.Map <SubCategoryReturnDTO>(sectionFroRepo); if ((sectionFroRepo == null)) { return(NotFound()); } return(Ok(sectionFroRepo)); }
[HttpPost("{VendorId}/{SubCategoryId}")]//done public async Task <IActionResult> CreateProduct(int VendorId, int subCategoryId, ProductRegisterDTO productRegisterDTO) { var sectionFromRepo = await _repo.GetSubCategory(subCategoryId); productRegisterDTO.SubCategoryId = sectionFromRepo.subCategoryID; var vendorFromRepo = await _repo.GetVendor(VendorId); productRegisterDTO.VendorId = vendorFromRepo.Id; var product = _mapper.Map <Product>(productRegisterDTO); _repo.Add(product); if (await _repo.SaveAll()) { var productToReturn = _mapper.Map <ProductReturnDTO>(product); return(CreatedAtRoute("GetProduct", new { id = product.ProductId }, productToReturn)); } throw new Exception("حدث مشكلة في حفظ Product"); }