private ProductViewModel FetchDataToModify(int id) { var product = _productRepository.GetProductInclById(id); // Find description fields not initialized yet (for example, some fields for category A have been set up AFTER product X within category A has been created) var populatedFields = _productRepository.GetProductDescItemsByProductId(product.Id); var requiredFields = _subcategoryRepository.GetProductDescFieldsBySubcat(product.SubcategoryId); var unpopulatedFields = requiredFields.Where(f => !populatedFields.Select(p => p.Field.Id).Contains(f.Id)).ToList(); foreach (var field in unpopulatedFields) { product.ProductDescriptionItems.Add(new ProductDescriptionItem { Field = field }); } // Persist changes for easier change tracking via existing extension if (unpopulatedFields.Count > 0) { _productRepository.SaveChanges(); } var vm = new ProductViewModel(); Object2ObjectMappings.ProductToProductViewModel(product, vm); PrepareNavData(id, "CPanelProductEdit"); return(vm); }
public IActionResult AdminView(int id) { var product = _productRepository.GetProductInclById(id); // map data to viewmodel var vm = new ProductViewModel(); Object2ObjectMappings.ProductToProductViewModel(product, vm); PrepareNavData(id, "CPanelProductView"); return(View("AdminView", vm)); }
public IActionResult Display(int id) { var userId = _userManager.GetUserId(User); var product = _productRepository.GetProductInclById(id); // map data to viewmodel var vm = new ProductViewModel(); Object2ObjectMappings.ProductToProductViewModel(product, vm); vm.NoUserAccount = String.IsNullOrEmpty(userId); vm.IsRatedByUser = _productRepository.ProductIsRatedByUserId(product.Id, userId); // check if availability is watched by existing user if (!product.IsAvailable && !vm.NoUserAccount) { vm.IsWatchedByUser = _productRepository.ProductIsWatchedByUserId(product.Id, userId); } PrepareNavData(id, "ProductDisplay"); return(View(vm)); }