示例#1
0
        [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");
        }
        public async Task <IActionResult> CreateProduct(int supplierId, int sectionId, ProductRegisterDTO productRegisterDTO)
        {
            var sectionFromRepo = await _repo.GetSection(sectionId);

            productRegisterDTO.SectionId = sectionFromRepo.SectionId;
            var supplierFromRepo = await _repo.GetSupplier(supplierId);

            productRegisterDTO.SupplierId = supplierFromRepo.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("حدث مشكلة في حفظ الرسالة الجديده");
        }