private async Task BindControlsAsync(DocumentTemplateViewModel model) { if (model == null) { model = new DocumentTemplateViewModel(); } model.Categories = _cache.GetCategory(1, 1); if (model.Products == null) { model.Products = new List <DocumentTemplateProductViewModel>(); } var products = await Uow.Products .Where(p => !p.IsDeleted) .Select(p => new DocumentTemplateProductViewModel { Id = p.Id, ProductNumber = p.ProductNumber, Name = p.Name, CategoryId = p.CategoryId, }).ToDictionaryAsync(p => p.Id, p => p); if (model.Products.IsNullOrEmpty()) { model.Products = products.Select(p => p.Value).ToList(); } else { foreach (var product in model.Products) { var tmp = products.TryGetValue(product.Id); if (tmp == null) { continue; } product.ProductNumber = tmp.ProductNumber; product.Name = tmp.Name; product.CategoryId = tmp.CategoryId; products.Remove(tmp.Id); } model.Products.AddRange(products.Values); } }
public IActionResult GetSubCategories(int id) { return(Ok(_cache.GetCategory(id, 1))); }