private IEnumerable <SubCategoryViewModel> GetSubCategoriesByCategoryId(int categoryId) { var listOfDbSubCatList = _subCategoryService.GetSubCategoriesByCategoryId(categoryId); IEnumerable <SubCategoryViewModel> listOfProductsVM = _mapper.Map <IEnumerable <SubCategoryViewModel> >(listOfDbSubCatList); ViewBag.CategoryName = listOfDbSubCatList.FirstOrDefault().Category.CategoryName.ToString(); return(listOfProductsVM); }
public IActionResult GetSubCategories(int id) { var subCategories = _subCategoryService.GetSubCategoriesByCategoryId(id); if (subCategories.Success) { var result = _mapper.Map <IEnumerable <SubCategoryForReturnDTO> >(subCategories.Data); return(Ok(result)); } return(BadRequest(subCategories.Message)); }
public ActionResult GetSubCategoriesByCategoryIdInJson(int categoryId) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Unauthorized()); } if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.ConsultationAdmin, true)) { return(Forbid()); } if (categoryId == null || categoryId == 0) { return(NotFound()); } //Server Side Parameters int start = Convert.ToInt32(Request.Form["start"].FirstOrDefault()); int length = Convert.ToInt32(Request.Form["length"]); string searchValue = Request.Form["search[value]"]; string sortColumnName = Request.Form["columns[" + Request.Form["order[0][column]"] + "][name]"]; string sortDirection = Request.Form["order[0][dir]"]; var subcategoryInDb = _subCategory.GetSubCategoriesByCategoryId(categoryId, start, length, searchValue, sortColumnName, sortDirection); var subCategory = new SubCategoryOutputModel { SubCategories = subcategoryInDb.Select(m => new SubCategoryModel { Id = m.Id, Name = m.Name, Description = m.Description, CategoryId = m.CategoryId, CategoryName = m.Category?.Name, IsActive = m.IsActive }).ToList() }; return(Json(new { data = subCategory.SubCategories })); }