Esempio n. 1
0
        public async Task <IActionResult> GetSection(int id)
        {
            var sectionFroRepo = await _repo.GetSection(id);

            var sections = _mapper.Map <SectionReturnDTO>(sectionFroRepo);

            if ((sectionFroRepo == null))
            {
                return(NotFound());
            }
            return(Ok(sectionFroRepo));
        }
        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("حدث مشكلة في حفظ الرسالة الجديده");
        }