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

            var post = _mapper.Map <CategoryReturnDTO>(categoryFroRepo);

            if ((categoryFroRepo == null))
            {
                return(NotFound());
            }
            return(Ok(categoryFroRepo));
        }
        public async Task <IActionResult> CreateSubCategory(int categoryId, SubCategoryRegisterDTO SubCategoryRegisterDTO)
        {
            var getCategory = await _repo.GetCategory(categoryId);

            SubCategoryRegisterDTO.CategoryId = getCategory.CategoryId;
            var subCategory = _mapper.Map <SubCategory>(SubCategoryRegisterDTO);

            _repo.Add(subCategory);
            if (await _repo.SaveAll())
            {
                var SubCategoryToReturn = _mapper.Map <SubCategoryReturnDTO>(subCategory);
                return(CreatedAtRoute("GetSubCategory", new { id = subCategory.subCategoryID }, SubCategoryToReturn));
            }
            throw new Exception("حدث مشكلة في حفظ الفئة الجديده");
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateSection(int categoryId, SectionRegisterDTO sectionRegisterDTO)
        {
            var getCategory = await _repo.GetCategory(categoryId);

            sectionRegisterDTO.CategoryId = getCategory.CategoryId;
            var section = _mapper.Map <Section>(sectionRegisterDTO);

            _repo.Add(section);
            if (await _repo.SaveAll())
            {
                var sectionToReturn = _mapper.Map <SectionReturnDTO>(section);
                return(CreatedAtRoute("GetSection", new { id = section.SectionId }, sectionToReturn));
            }
            throw new Exception("حدث مشكلة في حفظ الفئة الجديده");
        }