static void Main() { var productData = new List <Product>() { new Product { Id = 1, Name = "one" }, new Product { Id = 2, Name = "two" }, new Product { Id = 3, Name = "three" }, }; var genericRepository = new GenericRepository <Product>(productData); var spec = new GetProductSpecification(2); var product = genericRepository.GetById(spec); Console.WriteLine($"Single element:{product.Name}"); Console.WriteLine(); var spec2 = new GetProductSpecification(); var products = genericRepository.ListAll(spec2); foreach (var p in products) { Console.WriteLine($"{p.Id}.{p.Name}"); } }
public async Task <IList <ProductSpecificationModel> > Handle(GetProductSpecification request, CancellationToken cancellationToken) { if (request.Product == null) { throw new ArgumentNullException("product"); } string cacheKey = string.Format(ModelCacheEventConst.PRODUCT_SPECS_MODEL_KEY, request.Product.Id, request.Language.Id); return(await _cacheManager.GetAsync(cacheKey, async() => { var spa = new List <ProductSpecificationModel>(); foreach (var item in request.Product.ProductSpecificationAttributes.Where(x => x.ShowOnProductPage).OrderBy(x => x.DisplayOrder)) { var specificationAttribute = await _specificationAttributeService.GetSpecificationAttributeById(item.SpecificationAttributeId); var m = new ProductSpecificationModel { SpecificationAttributeId = item.SpecificationAttributeId, SpecificationAttributeName = specificationAttribute.GetLocalized(x => x.Name, request.Language.Id), ColorSquaresRgb = specificationAttribute.SpecificationAttributeOptions.Where(x => x.Id == item.SpecificationAttributeOptionId).FirstOrDefault() != null ? specificationAttribute.SpecificationAttributeOptions.Where(x => x.Id == item.SpecificationAttributeOptionId).FirstOrDefault().ColorSquaresRgb : "", GenericAttributes = specificationAttribute.GenericAttributes, }; switch (item.AttributeType) { case SpecificationAttributeType.Option: m.ValueRaw = WebUtility.HtmlEncode(specificationAttribute.SpecificationAttributeOptions.Where(x => x.Id == item.SpecificationAttributeOptionId).FirstOrDefault().GetLocalized(x => x.Name, request.Language.Id)); break; case SpecificationAttributeType.CustomText: m.ValueRaw = WebUtility.HtmlEncode(item.CustomValue); break; case SpecificationAttributeType.CustomHtmlText: m.ValueRaw = item.CustomValue; break; case SpecificationAttributeType.Hyperlink: m.ValueRaw = string.Format("<a href='{0}' target='_blank'>{0}</a>", item.CustomValue); break; default: break; } spa.Add(m); } return spa; } )); }
public async Task <IList <ProductSpecificationModel> > Handle(GetProductSpecification request, CancellationToken cancellationToken) { if (request.Product == null) { throw new ArgumentNullException(nameof(request.Product)); } var spa = new List <ProductSpecificationModel>(); foreach (var item in request.Product.ProductSpecificationAttributes.Where(x => x.ShowOnProductPage).OrderBy(x => x.DisplayOrder)) { var specificationAttribute = await _specificationAttributeService.GetSpecificationAttributeById(item.SpecificationAttributeId); var m = new ProductSpecificationModel { SpecificationAttributeId = item.SpecificationAttributeId, SpecificationAttributeName = specificationAttribute.GetTranslation(x => x.Name, request.Language.Id), ColorSquaresRgb = specificationAttribute.SpecificationAttributeOptions.Where(x => x.Id == item.SpecificationAttributeOptionId).FirstOrDefault() != null?specificationAttribute.SpecificationAttributeOptions.Where(x => x.Id == item.SpecificationAttributeOptionId).FirstOrDefault().ColorSquaresRgb : "", UserFields = specificationAttribute.UserFields, }; switch (item.AttributeTypeId) { case SpecificationAttributeType.Option: m.ValueRaw = WebUtility.HtmlEncode(specificationAttribute.SpecificationAttributeOptions.Where(x => x.Id == item.SpecificationAttributeOptionId).FirstOrDefault().GetTranslation(x => x.Name, request.Language.Id)); break; case SpecificationAttributeType.CustomText: m.ValueRaw = WebUtility.HtmlEncode(item.CustomValue); break; case SpecificationAttributeType.CustomHtmlText: m.ValueRaw = item.CustomValue; break; case SpecificationAttributeType.Hyperlink: m.ValueRaw = string.Format("<a href='{0}' target='_blank'>{0}</a>", item.CustomValue); break; default: break; } spa.Add(m); } return(spa); }
public async Task <GetProductSpecification> GetProductSpecificationForEdit(EntityDto input) { var output = new GetProductSpecification { }; List <IEnumerable <string> > result = new List <IEnumerable <string> >(); var ProductSpecification = _ProductSpecificationRepository .GetAll().Where(p => p.Id == input.Id).FirstOrDefault(); var SubListout = new List <GetProductSpecificationListDto>(); var AttributrGroups = (from r in _ProductGroupDetailRepository.GetAll() where r.ProductGroupId == ProductSpecification.ProductGroupId orderby r.OrderBy select new ProductSpecificationDetailList { Id = r.Id, AttributeGroupId = r.AttributeGroupId, AttributeGroupName = r.ProductAttributeGroups.AttributeGroupName, AttributeGroupCode = r.ProductAttributeGroups.AttributeGroupCode, }).ToArray(); foreach (var groups in AttributrGroups) { var OverAll = (from r in _AttributeGroupDetailRepository.GetAll() where r.AttributeGroupId == groups.AttributeGroupId select new AttributeGroupDetailListDto { AttributeGroupId = r.AttributeGroupId, AttributeGroupName = r.AttributeGroups.AttributeGroupName, AttributeId = r.AttributeId, AttributeName = r.Attributes.AttributeName, AttributeCode = r.Attributes.AttributeCode, ImgPath = r.Attributes.Imageurl, Selected = false }).ToArray(); foreach (var data in OverAll) { var Attributes = (from p in _ProdutSpecLinkRepository.GetAll() where p.ProductSpecificationId == input.Id && p.AttributeId == data.AttributeId select new SpesDretail { Id = p.Id, AttributeId = p.AttributeId }).FirstOrDefault(); if (Attributes != null) { data.Id = Attributes.Id; data.Selected = true; } } SubListout.Add(new GetProductSpecificationListDto { Id = groups.Id, Name = groups.AttributeGroupName, AttributeGroups = OverAll }); } output.productSpecificationDetails = SubListout.ToArray(); output.ProductSpecification = (from d in _ProductSpecificationRepository.GetAll() where d.Id == input.Id select new ProductSpecificationList { Id = d.Id, Name = d.Name, ImageUrl = d.ImageUrl, ProductGroupId = d.ProductGroupId, ProductGroupName = d.ProductGroups.ProductGroupName, Description = d.Description, Reset = d.Reset, BafcoMade = d.BafcoMade }).FirstOrDefault(); var datass = (from r in _ProdutSpecLinkRepository.GetAll() where r.ProductSpecificationId == input.Id group r by r.AttributeGroupId into g select new { GroupId = g.Key }); var idd = (int)output.ProductSpecification.ProductGroupId; var ProdutSpecs = (from r in datass join s in _ProductGroupDetailRepository.GetAll() on r.GroupId equals s.AttributeGroupId where s.ProductGroupId == idd select new { GroupId = r.GroupId, Orderby = s.OrderBy }).ToArray(); var ProdutSpecss = ProdutSpecs.OrderBy(c => c.Orderby).ToList(); if (ProdutSpecs.Count() > 0) { var FamilyCode = (from r in _ProdutSpecLinkRepository.GetAll() where r.ProductSpecificationId == input.Id group r by r.ProductGroups.prodFamily.ProductFamilyCode into g select g.Key).ToArray(); result.Add(FamilyCode); foreach (var d in ProdutSpecss) { var datas = (from r in _AttributeGroupDetailRepository.GetAll() join p in _ProdutSpecLinkRepository.GetAll() on r.AttributeId equals p.AttributeId where r.AttributeGroupId == d.GroupId && p.ProductSpecificationId == input.Id select r.Attributes.AttributeCode).ToArray(); result.Add(datas); } } Func <IEnumerable <IEnumerable <string> >, IEnumerable <IEnumerable <string> > > f0 = null; f0 = xss => { if (!xss.Any()) { return(new[] { Enumerable.Empty <string>() }); } else { var querys = from x in xss.First() from y in f0(xss.Skip(1)) select new[] { x }.Concat(y); return(querys); } }; Func <IEnumerable <IEnumerable <string> >, IEnumerable <string> > f = xss => f0(xss).Select(xs => String.Join("-", xs)); var results = f(result); var productCodes = results.ToArray(); var Created = (from r in _productRepository.GetAll() where r.ProductSpecificationId == input.Id select r.ProductCode).ToArray(); string[] same = Created.Intersect(productCodes).ToArray(); if (result.Count() > 0) { output.Available = productCodes.Count(); } else { output.Available = 0; } bool datamap = false; var records = _productRepository.GetAll().Where(p => p.ProductSpecificationId == input.Id).ToList(); foreach (var item in records) { var maprecord = _quotationProductRepository.GetAll().Where(p => p.ProductId == item.Id).Count(); if (maprecord > 0 && datamap == false) { datamap = true; } } output.DataMapped = datamap; output.Created = same.Count(); return(output); }