public CategoryListDto Convert(IEnumerable <Category> source, CategoryListDto destination, ResolutionContext context) { var categoryListDto = new CategoryListDto(); foreach (var category in source) { categoryListDto.Categories.Add(category.Name); } return(categoryListDto); }
public IActionResult GetById(string categoryId) { var result = _categoryService.GetById(categoryId); var cat = new CategoryListDto { CategoryName = result.Data.CategoryName, Id = result.Data.Id }; if (result.Success) { return(Ok(cat)); } return(BadRequest(result.Message)); }
public async Task <IActionResult> UpdateCategory(int id, [FromForm] CategoryListDto categoryListDto) { if (id == categoryListDto.Id) { return(BadRequest("Invalid Id")); } else { var updatedCategory = await _categoryService.GetByIdAsync(id); updatedCategory.Id = categoryListDto.Id; updatedCategory.Name = categoryListDto.Name; await _categoryService.UpdateAsync(updatedCategory); return(NoContent()); } }
private List <CategoryListDto> GetChildCategories(CategoryListDto categoryListDto) { List <CategoryListDto> categoryListDtos = new List <CategoryListDto>(); if (categoryListDto.SubCategoriesCount > 0) { var subCategories = dbContext.Categories.Include("SubCategories").Where(x => x.TopCategoryId == categoryListDto.Id).ToList(); categoryListDto.Categories = subCategories.ConvertToCategoryListDto(); foreach (var subCategory in categoryListDto.Categories) { GetChildCategories(subCategory); } } categoryListDtos.Add(categoryListDto); return(categoryListDtos); }
public async Task <List <CategoryListDto> > GetMenuCategory() { List <CategoryListDto> lstParent = new List <CategoryListDto>(); var categorys = await _unitOfWork.CategoryRepository.FindAll().ToListAsync(); foreach (var data in categorys) { CategoryListDto dataCategoryParent = new CategoryListDto(); if (data.ParentCategoryId == null) { dataCategoryParent.Name = data.Name; dataCategoryParent.Id = data.Id; dataCategoryParent.ParentCategoryId = data.ParentCategoryId; List <CategoryListDto> lstChild = new List <CategoryListDto>(); foreach (var data1 in categorys) { if (data1.ParentCategoryId == dataCategoryParent.Id) { CategoryListDto dataCategoryChild = new CategoryListDto(); dataCategoryChild.Name = data1.Name; dataCategoryChild.Id = data1.Id; dataCategoryChild.ParentCategoryId = data1.ParentCategoryId; List <CategoryListDto> lstChildren = new List <CategoryListDto>(); foreach (var data2 in categorys) { if (data2.ParentCategoryId == dataCategoryChild.Id) { CategoryListDto dataCategoryChildren = new CategoryListDto(); dataCategoryChildren.Name = data2.Name; dataCategoryChildren.Id = data2.Id; dataCategoryChildren.ParentCategoryId = data2.ParentCategoryId; lstChildren.Add(dataCategoryChildren); } } dataCategoryChild.listChildren = lstChildren; lstChild.Add(dataCategoryChild); } } dataCategoryParent.listChildren = lstChild; lstParent.Add(dataCategoryParent); } } return(lstParent); }
public ActionResult List(int?page, string shortName = "") { CategoryListDto activeCategory = null; int pageIndex = ((page != null && page.Value >= 1) ? page.Value : 1) - 1; var categoryList = _categoryAppService.GetCategorysOnShowAsync().Result; activeCategory = categoryList.FirstOrDefault(); ViewBag.ActiveCategory = activeCategory; if (!string.IsNullOrEmpty(shortName)) { var tempCategory = categoryList.FirstOrDefault(c => c.ShortName == shortName); if (tempCategory != null) { ViewBag.ActiveCategory = tempCategory; activeCategory = tempCategory; } } GetProductInput pagedInput = new GetProductInput() { CategoryId = activeCategory.Id, Sorting = "CreationTime" }; pagedInput.SkipCount = pageIndex * pagedInput.MaxResultCount; var products = _productAppService.GetPagedProductsAsync(pagedInput).Result; var pagedProducts = new StaticPagedList <ProductListDto>(products.Items, pageIndex + 1, pagedInput.MaxResultCount, products.TotalCount); ViewBag.SeoSetting = GetSeoSetting(); return(View(pagedProducts)); }
private ActionResult <IEnumerable <CategoryListDto> > GetMenu(CategoryListDto root, List <CategoryListDto> result) { foreach (var category in result) { var childCategories = dbContext.Categories.Include("SubCategories").Where(x => x.TopCategoryId == category.Id).Select(c => new CategoryListDto { Id = c.Id, Name = c.Name, TopCategoryId = c.TopCategoryId, SubCategoriesCount = c.SubCategories.Count }).ToList(); if (category.SubCategoriesCount != null && category.SubCategoriesCount != 0) { category.Categories = new List <CategoryListDto>(); GetMenu(category, childCategories); } if (root == null) { menu.Add(category); } else { root.Categories.Add(category); } } return(menu); }
public async Task<IDataResult<IList<CategoryListDto>>> GetCategoryListAsync() { var categoryListDtos = new List<CategoryListDto>(); IList<Category> categories = await _categoryDao.GetListAsync(); foreach (Category c in categories) { var categoryListDto = new CategoryListDto { CategoryId = c.Id, CategoryName = c.Name, CategoryDescription = c.Description, }; // Get Parent Category's data if it exists. if (c.ParentCategoryId != null) { var cat = await _categoryDao.GetAsync(p => p.Id == c.ParentCategoryId); categoryListDto.ParentCategoryId = cat.Id; categoryListDto.ParentCategoryName = cat.Name; } categoryListDtos.Add(categoryListDto); } return new SuccessDataResult<List<CategoryListDto>>(categoryListDtos); }