//public IEnumerable<SimpleProductViewModel> GetAllProduct() //{ // var queryResult = _pRepository.GetAllSimpleProduct(); // var result = queryResult; // //var config = new MapperConfiguration(cfg => // // cfg.CreateMap<ProductDTO ,ProductViewModel>() // // .ForMember(x => x.Color ,y => y.MapFrom(src => JsonConvert.DeserializeObject<IEnumerable<ColorViewModel>>(src.Color))) // // .ForMember(x => x.Depiction ,y => y.MapFrom(src => JsonConvert.DeserializeObject<DesprictionViewModel>(src.Depiction))) // //); // //var mapper = config.CreateMapper(); // //var pvm = mapper.Map<IEnumerable<ProductViewModel>>(queryResult).GroupBy(x => x.ID); // //var groupQueryResult = queryResult.GroupBy(x => x.ID).ToList(); // //IEnumerable<ProductViewModel> result = pvm.Zip(groupQueryResult ,(x ,y) => // //{ // // x.FirstOrDefault().ImgList = y.Select(z => z.Img); // // return x.FirstOrDefault(); // //}); // //var config = new MapperConfiguration(cfg => // // cfg.CreateMap<IGrouping<string ,ProductDTO> ,ProductViewModel>() // // .ForMember(x => x.Color ,y => y.MapFrom(src => JsonConvert.DeserializeObject<IEnumerable<ColorViewModel>>(src.FirstOrDefault().Color))) // // .ForMember(x => x.Depiction ,y => y.MapFrom(src => JsonConvert.DeserializeObject<DesprictionViewModel>(src.FirstOrDefault().Depiction))) // // .ForMember(x => x.ImgList ,y => y.MapFrom(src => src.Select(x => x.Img))) // // .ForAllOtherMembers(x => x.Ignore()) // //); // //var mapper = config.CreateMapper(); // //var pvm = mapper.Map<IEnumerable<ProductViewModel>>(queryResult); // return result; //} public ProductTableViewModel GetProductTable() { var ptvm = new ProductTableViewModel() { FiledList = new List <string>() { "ID", "Name", "ClassName", "ManufacturerName", "Color", "InvetoryQuantity", "Price" }, SvmList = GetAllProduct() }; return(ptvm); }
public ActionResult Index() { ProductTableViewModel model = new ProductTableViewModel(); model.Categories = _categoryService.GetAllCategories().Categories.Select(u => new SelectListItem() { Text = u.CategoryName, Value = u.CategoryID.ToString() }).ToList(); model.Suppliers = _supplierService.GetAllSuppliers().Suppliers.Select(u => new SelectListItem() { Text = u.CompanyName, Value = u.SupplierID.ToString() }).ToList(); return(View("../Datatables/ProductTable", model)); }