public async Task <RespContainer <ItemResponse> > Handle(AddItemCommand request, CancellationToken cancellationToken) { Models.Item item = _itemMapper.Map(request.Data); Models.Item result = _itemRespository.Add(item); int modifiedRecords = await _itemRespository.UnitOfWork.SaveChangesAsync(); _logger.LogInformation(Events.Add, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords); _logger.LogInformation(Events.Add, Messages.ChangesApplied_id, result?.Id); return(RespContainer.Ok(_itemMapper.Map(result), "Item Created")); }
public void HandleMapping <TModel>(TModel model, Item item, IPropertyMeta propertyMeta, ICache cache, IItemMapper itemMapper) { var childMapPropertyMeta = propertyMeta as IChildMappingPropertyMeta; if (childMapPropertyMeta == null || model.GetType().GetProperty(propertyMeta.PropertyName).Equals(null)) { return; } var property = model.GetType().GetProperty(propertyMeta.PropertyName); var listType = property.PropertyType.GetGenericArguments()[0]; var genericList = typeof(List <>).MakeGenericType(listType); var collection = Activator.CreateInstance(genericList) as IList; if (collection == null) { return; } var parentItem = GetParentItemForChildCollection(item, childMapPropertyMeta); if (parentItem != null) { foreach (Item childItem in parentItem.Children) { var childObject = Activator.CreateInstance(listType) as dynamic; itemMapper.Map(childObject, childItem); collection.Add(childObject); } } property.SetValue(model, collection); }
public void HandleMapping <TModel>(TModel model, Item item, IPropertyMeta propertyMeta, ICache cache, IItemMapper itemMapper) { var listField = (MultilistField)item.Fields[propertyMeta.MappingName]; if (listField == null) { return; } var listItems = listField.GetItems(); var property = model.GetType().GetProperty(propertyMeta.PropertyName); var listType = property.PropertyType.GetGenericArguments()[0]; var genericList = typeof(List <>).MakeGenericType(listType); var collection = Activator.CreateInstance(genericList) as IList; if (collection == null) { return; } foreach (var linkedItem in listItems) { var childObject = Activator.CreateInstance(listType) as dynamic; itemMapper.Map(childObject, linkedItem); collection.Add(childObject); } property.SetValue(model, collection); }
public async Task <IEnumerable <ItemResponse> > GetItemsAsync() { var result = await _itemRepository.GetAsync(); return(result .Select(x => _itemMapper.Map(x))); }
public async Task <ItemResponse> AddItemAsync(AddItemRequest request) { Item item = _itemMapper.Map(request); Item result = _itemRespository.Add(item); int modifiedRecords = await _itemRespository.UnitOfWork.SaveChangesAsync(); _logger.LogInformation(Events.Add, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords); _logger.LogInformation(Events.Add, Messages.ChangesApplied_id, result?.Id); return(_itemMapper.Map(result)); }
public async Task <IEnumerable <ItemResponse> > GetItemsAsync() { var result = await _itemRepository.GetAsync(); _logger.LogInformation(Events.GetById, Messages.NumberOfRecordAffected_modifiedRecords, result.Count()); return(result .Select(x => _itemMapper.Map(x))); }
public IEnumerable <SortOrderOption> GetAll() { return(this.cacheService.CreateOrGet( "DSP.Business.Search.Sorting.SortOptions", () => { return Sitecore.Context.Database.GetItem(sortOptionsRoot) .Children .Select(i => itemMapper.Map <SortOrderOption>(i)) .ToList(); })); }
public SiteConfiguration GetSiteConfiguration(Item siteRootItem) { return (_cacheService.CreateOrGet( $"DSP.Foundation.Configuration.SiteConfiguration.{siteRootItem.Name}", () => { var configItem = siteRootItem.GetFieldValueAsItem(SitecoreTemplates.Site_Setting.SiteSettingItem.FieldName); var config = _itemMapper.Map <SiteConfiguration>(configItem); config.ConfigItem = configItem; return config; })); }
public async Task <ItemResponse> AddItemAsync(AddItemRequest request) { var item = _itemMapper.Map(request); var result = _itemRepository.Add(item); await _itemRepository.UnitOfWork.SaveChangesAsync(); return(_itemMapper.Map(result)); }
private void HandleLinkedObjectMapping <TModel>(TModel model, Item item, IPropertyMeta propertyMeta, IItemMapper itemMapper) { Guid guid; if (!Guid.TryParse(item[propertyMeta.MappingName], out guid)) { return; } var linkedItem = global::Sitecore.Context.Database.GetItem(new ID(guid)); if (linkedItem == null) { return; } var property = model.GetType().GetProperty(propertyMeta.PropertyName); var linkedObject = Activator.CreateInstance(property.PropertyType) as dynamic; itemMapper.Map(linkedObject, linkedItem); property.SetValue(model, linkedObject); }