private async Task <IHttpActionResult> Save(RelationshipFieldDTO relationshipFieldDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isNew = relationshipFieldDTO.RelationshipFieldId == Guid.Empty; RelationshipField relationshipField; if (isNew) { relationshipField = new RelationshipField(); DbContext.Entry(relationshipField).State = EntityState.Added; } else { relationshipField = await DbContext.RelationshipFields.SingleOrDefaultAsync(o => o.RelationshipFieldId == relationshipFieldDTO.RelationshipFieldId); if (relationshipField == null) { return(NotFound()); } DbContext.Entry(relationshipField).State = EntityState.Modified; } ModelFactory.Hydrate(relationshipField, relationshipFieldDTO); await DbContext.SaveChangesAsync(); return(await Get(relationshipField.RelationshipFieldId)); }
/// <summary> /// Gets a lists of target items from a relationship field /// </summary> /// <param name="field">the relationship field</param> /// <param name="relationshipName">the relationship name, for example upsell</param> /// <returns>a list of relationship targets or null if no items found</returns> protected List <Item> GetRelationshipsFromField(RelationshipField field, string relationshipName) { List <Item> items = null; IEnumerable <Item> relationships = field.GetRelationshipsTargets(relationshipName); if (relationships != null) { items = new List <Item>(relationships); } return(items); }
public RelatedCatalogItemsViewModel GetRelationshipsFromItem(Item catalogItem, Rendering rendering) { if (catalogItem == null || !catalogItem.IsDerived(Foundation.Commerce.Templates.Commerce.CatalogItem.Id) || !catalogItem.FieldHasValue(Foundation.Commerce.Templates.Commerce.CatalogItem.Fields.RelationshipList)) { return(null); } RelationshipField field = catalogItem.Fields[Foundation.Commerce.Templates.Commerce.CatalogItem.Fields.RelationshipList]; var model = new RelatedCatalogItemsViewModel(); var productRelationshipInfoList = field.GetRelationships(); productRelationshipInfoList = productRelationshipInfoList.OrderBy(x => x.Rank); var productModelList = GroupRelationshipsByDescription(productRelationshipInfoList); model.RelatedProducts.AddRange(productModelList); return(model); }
public RelatedCatalogItemsViewModel GetRelationshipsFromItem([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, Item catalogItem, Rendering rendering) { Assert.ArgumentNotNull(storefront, "storefront"); if (catalogItem != null && catalogItem.Fields.Contains(CommerceConstants.KnownFieldIds.RelationshipList) && !string.IsNullOrEmpty(catalogItem[CommerceConstants.KnownFieldIds.RelationshipList])) { var field = new RelationshipField(catalogItem.Fields[CommerceConstants.KnownFieldIds.RelationshipList]); if (rendering != null && !string.IsNullOrWhiteSpace(rendering.RenderingItem.InnerItem["RelationshipsToDisplay"])) { var relationshipsToDisplay = rendering.RenderingItem.InnerItem["RelationshipsToDisplay"].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); return(this.GetRelationshipsFromField(storefront, visitorContext, field, rendering, relationshipsToDisplay)); } else { return(this.GetRelationshipsFromField(storefront, visitorContext, field, rendering)); } } return(null); }
protected IEnumerable <CategoryViewModel> GroupRelationshipsByDescription([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, RelationshipField field, IEnumerable <string> relationshipNames, IEnumerable <CatalogRelationshipInformation> productRelationshipInfoList, Rendering rendering) { Dictionary <string, CategoryViewModel> relationshipGroups = new Dictionary <string, CategoryViewModel>(StringComparer.OrdinalIgnoreCase); if (field != null && productRelationshipInfoList != null) { foreach (var relationshipInfo in productRelationshipInfoList) { if (!relationshipNames.Any() || relationshipNames.Contains(relationshipInfo.RelationshipName, StringComparer.OrdinalIgnoreCase)) { Item lookupItem = null; bool usingRelationshipName = string.IsNullOrWhiteSpace(relationshipInfo.RelationshipDescription); var relationshipDescription = string.IsNullOrWhiteSpace(relationshipInfo.RelationshipDescription) ? StorefrontManager.GetRelationshipName(relationshipInfo.RelationshipName, out lookupItem) : relationshipInfo.RelationshipDescription; CategoryViewModel categoryModel = null; if (!relationshipGroups.TryGetValue(relationshipDescription, out categoryModel)) { categoryModel = new CategoryViewModel { ChildProducts = new List <ProductViewModel>(), RelationshipName = relationshipInfo.RelationshipName, RelationshipDescription = relationshipDescription, LookupRelationshipItem = (usingRelationshipName) ? lookupItem : null }; relationshipGroups[relationshipDescription] = categoryModel; } var targetItemId = ID.Parse(relationshipInfo.ToItemExternalId); var targetItem = field.InnerField.Database.GetItem(targetItemId); var productModel = new ProductViewModel(targetItem); productModel.Initialize(rendering); this.GetProductRating(targetItem); categoryModel.ChildProducts.Add(productModel); } } } if (relationshipGroups.Count > 0) { List <ProductViewModel> productViewModelList = new List <ProductViewModel>(); foreach (string key in relationshipGroups.Keys) { CategoryViewModel viewModel = relationshipGroups[key]; var childProducts = viewModel.ChildProducts; if (childProducts != null && childProducts.Count > 0) { productViewModelList.AddRange(childProducts); } } if (productViewModelList.Count > 0) { this.GetProductBulkPrices(visitorContext, productViewModelList); this.InventoryManager.GetProductsStockStatusForList(storefront, productViewModelList); } } return(relationshipGroups.Values); }
/// <summary> /// Gets a lists of target items from a relationship field /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="field">the relationship field</param> /// <param name="rendering">The target renering.</param> /// <param name="relationshipNames">the names of the relationships, to retrieve (for example upsell).</param> /// <returns> /// a list of relationship targets or null if no items found /// </returns> public RelatedCatalogItemsViewModel GetRelationshipsFromField([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, RelationshipField field, Rendering rendering, IEnumerable <string> relationshipNames) { Assert.ArgumentNotNull(storefront, "storefront"); relationshipNames = relationshipNames ?? Enumerable.Empty <string>(); relationshipNames = relationshipNames.Select(s => s.Trim()); var model = new RelatedCatalogItemsViewModel(); if (field != null) { var productRelationshipInfoList = field.GetRelationships(); productRelationshipInfoList = productRelationshipInfoList.OrderBy(x => x.Rank); var productModelList = this.GroupRelationshipsByDescription(storefront, visitorContext, field, relationshipNames, productRelationshipInfoList, rendering); model.RelatedProducts.AddRange(productModelList); } model.Initialize(rendering); return(model); }
/// <summary> /// Gets a lists of target items from a relationship field /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="field">the relationship field</param> /// <param name="rendering">The target renering.</param> /// <returns> /// a list of relationship targets or null if no items found /// </returns> public RelatedCatalogItemsViewModel GetRelationshipsFromField([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, RelationshipField field, Rendering rendering) { Assert.ArgumentNotNull(storefront, "storefront"); return(GetRelationshipsFromField(storefront, visitorContext, field, rendering, null)); }
protected IEnumerable<CategoryViewModel> GroupRelationshipsByDescription([NotNull] CommerceStorefront storefront, RelationshipField field, IEnumerable<string> relationshipNames, IEnumerable<CatalogRelationshipInformation> productRelationshipInfoList, Rendering rendering) { Dictionary<string, CategoryViewModel> relationshipGroups = new Dictionary<string, CategoryViewModel>(StringComparer.OrdinalIgnoreCase); if (field != null && productRelationshipInfoList != null) { foreach (var relationshipInfo in productRelationshipInfoList) { if (!relationshipNames.Any() || relationshipNames.Contains(relationshipInfo.RelationshipName, StringComparer.OrdinalIgnoreCase)) { var relationshipDescription = string.IsNullOrWhiteSpace(relationshipInfo.RelationshipDescription) ? relationshipInfo.RelationshipName : relationshipInfo.RelationshipDescription; CategoryViewModel categoryModel = null; if (!relationshipGroups.TryGetValue(relationshipDescription, out categoryModel)) { categoryModel = new CategoryViewModel { ChildProducts = new List<ProductViewModel>(), RelationshipName = relationshipInfo.RelationshipName, RelationshipDescription = relationshipDescription }; relationshipGroups[relationshipDescription] = categoryModel; } var targetItemId = ID.Parse(relationshipInfo.ToItemExternalId); var targetItem = field.InnerField.Database.GetItem(targetItemId); var productModel = new ProductViewModel(targetItem); productModel.Initialize(rendering); this.GetProductRating(targetItem); categoryModel.ChildProducts.Add(productModel); } } } if (relationshipGroups.Count > 0) { List<ProductViewModel> productViewModelList = new List<ProductViewModel>(); foreach (string key in relationshipGroups.Keys) { CategoryViewModel viewModel = relationshipGroups[key]; var childProducts = viewModel.ChildProducts; if (childProducts != null && childProducts.Count > 0) { productViewModelList.AddRange(childProducts); } } if (productViewModelList.Count > 0) { this.GetProductBulkPrices(productViewModelList); this.InventoryManager.GetProductsStockStatus(storefront, productViewModelList); } } return relationshipGroups.Values; }
public RelatedCatalogItemsViewModel GetRelationshipsFromItem([NotNull] CommerceStorefront storefront, Item catalogItem, Rendering rendering) { Assert.ArgumentNotNull(storefront, "storefront"); if (catalogItem != null && catalogItem.Fields.Contains(CommerceConstants.KnownFieldIds.RelationshipList) && !string.IsNullOrEmpty(catalogItem[CommerceConstants.KnownFieldIds.RelationshipList])) { var field = new RelationshipField(catalogItem.Fields[CommerceConstants.KnownFieldIds.RelationshipList]); if (rendering != null && !string.IsNullOrWhiteSpace(rendering.RenderingItem.InnerItem["RelationshipsToDisplay"])) { var relationshipsToDisplay = rendering.RenderingItem.InnerItem["RelationshipsToDisplay"].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); return this.GetRelationshipsFromField(storefront, field, rendering, relationshipsToDisplay); } else { return this.GetRelationshipsFromField(storefront, field, rendering); } } return null; }
/// <summary> /// Gets a lists of target items from a relationship field /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="field">the relationship field</param> /// <param name="rendering">The target renering.</param> /// <param name="relationshipNames">the names of the relationships, to retrieve (for example upsell).</param> /// <returns> /// a list of relationship targets or null if no items found /// </returns> public RelatedCatalogItemsViewModel GetRelationshipsFromField([NotNull] CommerceStorefront storefront, RelationshipField field, Rendering rendering, IEnumerable<string> relationshipNames) { Assert.ArgumentNotNull(storefront, "storefront"); relationshipNames = relationshipNames ?? Enumerable.Empty<string>(); relationshipNames = relationshipNames.Select(s => s.Trim()); var model = new RelatedCatalogItemsViewModel(); if (field != null) { var productRelationshipInfoList = field.GetProductRelationships(); var productModelList = this.GroupRelationshipsByDescription(storefront, field, relationshipNames, productRelationshipInfoList, rendering); model.RelatedProducts.AddRange(productModelList); var categoryRelationshipInfoList = field.GetCategoryRelationships(); var categoryModelList = this.GroupRelationshipsByDescription(storefront, field, relationshipNames, categoryRelationshipInfoList, rendering); model.RelatedCategories.AddRange(categoryModelList); } model.Initialize(rendering); return model; }
/// <summary> /// Gets a lists of target items from a relationship field /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="field">the relationship field</param> /// <param name="rendering">The target renering.</param> /// <returns> /// a list of relationship targets or null if no items found /// </returns> public RelatedCatalogItemsViewModel GetRelationshipsFromField([NotNull] CommerceStorefront storefront, RelationshipField field, Rendering rendering) { Assert.ArgumentNotNull(storefront, "storefront"); return GetRelationshipsFromField(storefront, field, rendering, null); }
static RelationshipGroupRecordCheck() { IList <RecordField <RelationshipGroupRecord, ConsistencyReport_RelationshipGroupConsistencyReport> > list = new List <RecordField <RelationshipGroupRecord, ConsistencyReport_RelationshipGroupConsistencyReport> >(); list.Add(RelationshipTypeField.RelationshipType); list.Add(GroupField.Next); list.Add(NodeField.Owner); ((IList <RecordField <RelationshipGroupRecord, ConsistencyReport_RelationshipGroupConsistencyReport> >)list).AddRange(asList(RelationshipField.values())); _fields = Collections.unmodifiableList(list); }
/// <summary> /// Gets a lists of target items from a relationship field /// </summary> /// <param name="field">the relationship field</param> /// <param name="relationshipName">the relationship name, for example upsell</param> /// <returns>a list of relationship targets or null if no items found</returns> protected List<Item> GetRelationshipsFromField(RelationshipField field, string relationshipName) { List<Item> items = null; IEnumerable<Item> relationships = field.GetRelationshipsTargets(relationshipName); if (relationships != null) { items = new List<Item>(relationships); } return items; }