public static dataModel.Contact ToDataModel(this coreModel.Contact contact, PrimaryKeyResolvingMap pkMap) { if (contact == null) throw new ArgumentNullException("contact"); var retVal = new dataModel.Contact(); contact.ToDataModel(retVal); if (retVal.Name == null) { retVal.Name = retVal.FullName; } pkMap.AddPair(contact, retVal); if (contact.Organizations != null) { retVal.MemberRelations = new ObservableCollection<dataModel.MemberRelation>(); foreach (var organization in contact.Organizations) { var memberRelation = new dataModel.MemberRelation { AncestorId = organization, AncestorSequence = 1, DescendantId = retVal.Id, }; retVal.MemberRelations.Add(memberRelation); } } return (dataModel.Contact)retVal; }
public void Update(coreModel.Contact[] contacts) { var pkMap = new PrimaryKeyResolvingMap(); using (var repository = _repositoryFactory()) using (var changeTracker = GetChangeTracker(repository)) { foreach (var contact in contacts) { var targetEntity = repository.GetContactById(contact.Id); if (targetEntity != null) { changeTracker.Attach(targetEntity); var sourceEntity = contact.ToDataModel(pkMap); sourceEntity.Patch(targetEntity); _dynamicPropertyService.SaveDynamicPropertyValues(contact); } } CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } }
public static ShipmentItemEntity ToDataModel(this ShipmentItem shipmentItem, ShoppingCartEntity cartEntity, PrimaryKeyResolvingMap pkMap) { if (shipmentItem == null) throw new ArgumentNullException("shipmentItem"); var retVal = new ShipmentItemEntity(); pkMap.AddPair(shipmentItem, retVal); retVal.InjectFrom(shipmentItem); //Try to find cart line item by shipment item if(!String.IsNullOrEmpty(shipmentItem.LineItemId)) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.Id == shipmentItem.LineItemId); } if(retVal.LineItem == null && shipmentItem.LineItem != null) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.Id == shipmentItem.LineItem.Id); } if (retVal.LineItem == null && shipmentItem.LineItem != null) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.ProductId == shipmentItem.LineItem.ProductId); } if(retVal.LineItem != null && !String.IsNullOrEmpty(retVal.LineItem.Id)) { retVal.LineItemId = retVal.LineItem.Id; retVal.LineItem = null; } return retVal; }
public void Create(coreModel.CatalogProduct[] items) { var pkMap = new PrimaryKeyResolvingMap(); using (var repository = _catalogRepositoryFactory()) { foreach (var item in items) { var dbItem = item.ToDataModel(pkMap); repository.Add(dbItem); if (item.Variations != null) { foreach (var variation in item.Variations) { variation.MainProductId = dbItem.Id; variation.CatalogId = dbItem.CatalogId; var dbVariation = variation.ToDataModel(pkMap); repository.Add(dbVariation); } } } CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } //Update SEO var itemsWithVariations = items.Concat(items.Where(x => x.Variations != null).SelectMany(x => x.Variations)).ToArray(); _commerceService.UpsertSeoForObjects(itemsWithVariations); }
public override MemberDataEntity FromMember(Member member, PrimaryKeyResolvingMap pkMap) { var contact = member as Contact; if (contact != null) { if (string.IsNullOrEmpty(this.Name)) { this.Name = contact.FullName; } pkMap.AddPair(contact, this); if (contact.Organizations != null) { this.MemberRelations = new ObservableCollection<MemberRelationDataEntity>(); foreach (var organization in contact.Organizations) { var memberRelation = new MemberRelationDataEntity { AncestorId = organization, AncestorSequence = 1, DescendantId = this.Id, }; this.MemberRelations.Add(memberRelation); } } } //Call base converter return base.FromMember(member, pkMap); }
public void Update(coreModel.Organization[] organizations) { var pkMap = new PrimaryKeyResolvingMap(); using (var repository = _repositoryFactory()) using (var changeTracker = GetChangeTracker(repository)) { foreach (var organization in organizations) { var sourceEntity = organization.ToDataModel(pkMap); var targetEntity = repository.GetOrganizationById(organization.Id); if (targetEntity == null) { throw new NullReferenceException("targetEntity"); } changeTracker.Attach(targetEntity); sourceEntity.Patch(targetEntity); } CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } foreach (var organization in organizations) { _dynamicPropertyService.SaveDynamicPropertyValues(organization); } }
public static ShipmentEntity ToDataModel(this Shipment shipment, ShoppingCartEntity cartEntity, PrimaryKeyResolvingMap pkMap) { if (shipment == null) throw new ArgumentNullException("shipment"); var retVal = new ShipmentEntity(); pkMap.AddPair(shipment, retVal); retVal.InjectFrom(shipment); retVal.Currency = shipment.Currency.ToString(); if (shipment.DeliveryAddress != null) { retVal.Addresses = new ObservableCollection<AddressEntity>(new AddressEntity[] { shipment.DeliveryAddress.ToDataModel() }); } if (shipment.Items != null) { retVal.Items = new ObservableCollection<ShipmentItemEntity>(shipment.Items.Select(x => x.ToDataModel(cartEntity, pkMap))); } if (shipment.TaxDetails != null) { retVal.TaxDetails = new ObservableCollection<TaxDetailEntity>(); retVal.TaxDetails.AddRange(shipment.TaxDetails.Select(x => x.ToDataModel())); } if (shipment.Discounts != null) { retVal.Discounts = new ObservableCollection<DiscountEntity>(); retVal.Discounts.AddRange(shipment.Discounts.Select(x => x.ToDataModel(pkMap))); } return retVal; }
public static dataModel.Organization ToDataModel(this coreModel.Organization organization, PrimaryKeyResolvingMap pkMap) { if (organization == null) throw new ArgumentNullException("organization"); var retVal = new dataModel.Organization(); pkMap.AddPair(organization, retVal); retVal.InjectFrom(organization); if (organization.Phones != null) { retVal.Phones = new ObservableCollection<dataModel.Phone>(organization.Phones.Select(x => new dataModel.Phone { Number = x, MemberId = organization.Id })); } if (organization.Emails != null) { retVal.Emails = new ObservableCollection<dataModel.Email>(organization.Emails.Select(x => new dataModel.Email { Address = x, MemberId = organization.Id })); } if (organization.Addresses != null) { retVal.Addresses = new ObservableCollection<dataModel.Address>(organization.Addresses.Select(x => x.ToDataModel())); foreach (var address in retVal.Addresses) { address.MemberId = organization.Id; } } if (organization.Notes != null) { retVal.Notes = new ObservableCollection<dataModel.Note>(organization.Notes.Select(x => x.ToDataModel())); foreach (var note in retVal.Notes) { note.MemberId = organization.Id; } } if (organization.ParentId != null) { retVal.MemberRelations = new ObservableCollection<dataModel.MemberRelation>(); var memberRelation = new dataModel.MemberRelation { AncestorId = organization.ParentId, DescendantId = organization.Id, AncestorSequence = 1 }; retVal.MemberRelations.Add(memberRelation); } return retVal; }
public static ShipmentEntity ToDataModel(this Shipment shipment, CustomerOrderEntity orderEntity, PrimaryKeyResolvingMap pkMap) { if (shipment == null) throw new ArgumentNullException("shipment"); var retVal = new ShipmentEntity(); retVal.InjectFrom(shipment); pkMap.AddPair(shipment, retVal); retVal.Currency = shipment.Currency.ToString(); //Allow to empty address retVal.Addresses = new ObservableCollection<AddressEntity>(); if (shipment.DeliveryAddress != null) { retVal.Addresses = new ObservableCollection<AddressEntity>(new AddressEntity[] { shipment.DeliveryAddress.ToDataModel() }); } if(shipment.Items != null) { retVal.Items = new ObservableCollection<ShipmentItemEntity>(shipment.Items.Select(x=>x.ToDataModel(orderEntity, pkMap))); } if (shipment.Packages != null) { retVal.Packages = new ObservableCollection<ShipmentPackageEntity>(shipment.Packages.Select(x => x.ToDataModel(orderEntity, pkMap))); } if (shipment.TaxDetails != null) { retVal.TaxDetails = new ObservableCollection<TaxDetailEntity>(); retVal.TaxDetails.AddRange(shipment.TaxDetails.Select(x => x.ToDataModel())); } return retVal; }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="catalog"></param> /// <returns></returns> public static dataModel.Catalog ToDataModel(this coreModel.Catalog catalog, PrimaryKeyResolvingMap pkMap) { if (catalog == null) throw new ArgumentNullException("catalog"); if(catalog.DefaultLanguage == null) throw new NullReferenceException("DefaultLanguage"); var retVal = new dataModel.Catalog(); pkMap.AddPair(catalog, retVal); if (catalog.PropertyValues != null) { retVal.CatalogPropertyValues = new ObservableCollection<dataModel.PropertyValue>(); retVal.CatalogPropertyValues.AddRange(catalog.PropertyValues.Select(x => x.ToDataModel(pkMap))); } retVal.InjectFrom(catalog); retVal.DefaultLanguage = catalog.DefaultLanguage.LanguageCode; if (catalog.Languages != null) { retVal.CatalogLanguages = new ObservableCollection<dataModel.CatalogLanguage>(); retVal.CatalogLanguages.AddRange(catalog.Languages.Select(x => x.ToDataModel())); } return retVal; }
/// <summary> /// Converting to foundation type /// </summary> public static dataModel.Asset ToDataModel(this coreModel.Asset asset, PrimaryKeyResolvingMap pkMap) { if (asset == null) throw new ArgumentNullException("asset"); var retVal = new dataModel.Asset(); pkMap.AddPair(asset, retVal); retVal.InjectFrom(asset); return retVal; }
/// <summary> /// Converting to foundation type /// </summary> public static dataModel.Image ToDataModel(this coreModel.Image image, PrimaryKeyResolvingMap pkMap) { if (image == null) throw new ArgumentNullException("image"); var retVal = new dataModel.Image(); pkMap.AddPair(image, retVal); retVal.InjectFrom(image); return retVal; }
public IEnumerable<QuoteRequest> SaveChanges(QuoteRequest[] quoteRequests) { if (quoteRequests == null) { throw new ArgumentNullException("quoteRequests"); } //Generate Number EnsureThatQuoteHasNumber(quoteRequests); var pkMap = new PrimaryKeyResolvingMap(); using (var repository = _repositoryFactory()) { var ids = quoteRequests.Where(x => x.Id != null).Select(x => x.Id).Distinct().ToArray(); var origDbQuotes = repository.GetQuoteRequestByIds(ids); using (var changeTracker = GetChangeTracker(repository)) { //Update foreach (var origDbQuote in origDbQuotes) { var changedQuote = quoteRequests.First(x => x.Id == origDbQuote.Id); // Do business logic on quote request _eventPublisher.Publish(new QuoteRequestChangeEvent(EntryState.Modified, GetByIds(new[] { origDbQuote.Id }).First(), changedQuote)); var changedDbQuote = changedQuote.ToDataModel(pkMap); changeTracker.Attach(origDbQuote); changedDbQuote.Patch(origDbQuote); } //Create var newQuotes = quoteRequests.Where(x => !origDbQuotes.Any(y => y.Id == x.Id)); foreach(var newQuote in newQuotes) { // Do business logic on quote request _eventPublisher.Publish(new QuoteRequestChangeEvent(EntryState.Added, newQuote, newQuote)); var newDbQuote = newQuote.ToDataModel(pkMap); repository.Add(newDbQuote); } repository.UnitOfWork.Commit(); //Copy generated id from dbEntities to model pkMap.ResolvePrimaryKeys(); } //Save dynamic properties foreach (var quoteRequest in quoteRequests) { _dynamicPropertyService.SaveDynamicPropertyValues(quoteRequest); } return quoteRequests; } }
public static dataModel.DynamicContentItem ToDataModel(this coreModel.DynamicContentItem contentItem, PrimaryKeyResolvingMap pkMap) { if (contentItem == null) throw new ArgumentNullException("contentItem"); var retVal = new dataModel.DynamicContentItem(); pkMap.AddPair(contentItem, retVal); retVal.InjectFrom(contentItem); retVal.ContentTypeId = contentItem.ContentType; return retVal; }
public coreModel.Catalog Create(coreModel.Catalog catalog) { var pkMap = new PrimaryKeyResolvingMap(); var dbCatalog = catalog.ToDataModel(pkMap); coreModel.Catalog retVal = null; using (var repository = _catalogRepositoryFactory()) { repository.Add(dbCatalog); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } retVal = GetById(dbCatalog.Id); return retVal; }
public static ShipmentPackageEntity ToDataModel(this ShipmentPackage package, CustomerOrderEntity orderEntity, PrimaryKeyResolvingMap pkMap) { if (package == null) throw new ArgumentNullException("package"); var retVal = new ShipmentPackageEntity(); pkMap.AddPair(package, retVal); retVal.InjectFrom(package); if(package.Items != null) { retVal.Items = new ObservableCollection<ShipmentItemEntity>(package.Items.Select(x => x.ToDataModel(orderEntity, pkMap))); } return retVal; }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="itemAsset">The item asset.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">itemAsset</exception> public static dataModel.EditorialReview ToDataModel(this coreModel.EditorialReview review, dataModel.Item product, PrimaryKeyResolvingMap pkMap) { if (review == null) throw new ArgumentNullException("review"); var retVal = new dataModel.EditorialReview(); pkMap.AddPair(review, retVal); retVal.InjectFrom(review); retVal.ItemId = product.Id; retVal.Source = review.ReviewType; retVal.ReviewState = (int)coreModel.ReviewState.Active; retVal.Locale = review.LanguageCode; return retVal; }
public static dataModel.QuoteItemEntity ToDataModel(this coreModel.QuoteItem quoteItem, PrimaryKeyResolvingMap pkMap) { if (quoteItem == null) throw new ArgumentNullException("quoteItem"); var retVal = new dataModel.QuoteItemEntity(); pkMap.AddPair(quoteItem, retVal); retVal.InjectFrom(quoteItem); retVal.Currency = quoteItem.Currency.ToString(); if (quoteItem.ProposalPrices != null) { retVal.ProposalPrices = new ObservableCollection<dataModel.TierPriceEntity>(quoteItem.ProposalPrices.Select(x => x.ToDataModel())); } return retVal; }
public static PaymentEntity ToDataModel(this Payment payment, PrimaryKeyResolvingMap pkMap) { if (payment == null) throw new ArgumentNullException("payment"); var retVal = new PaymentEntity(); pkMap.AddPair(payment, retVal); retVal.InjectFrom(payment); retVal.Currency = payment.Currency.ToString(); if (payment.BillingAddress != null) { retVal.Addresses = new ObservableCollection<AddressEntity>(new AddressEntity[] { payment.BillingAddress.ToDataModel() }); } return retVal; }
public coreModel.Organization Create(coreModel.Organization organization) { var pkMap = new PrimaryKeyResolvingMap(); var entity = organization.ToDataModel(pkMap); using (var repository = _repositoryFactory()) { repository.Add(entity); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } _dynamicPropertyService.SaveDynamicPropertyValues(organization); var retVal = GetById(entity.Id); return retVal; }
/// <summary> /// Converting to foundation type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="propValue">The property value.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">propValue</exception> public static dataModel.PropertyValue ToDataModel(this coreModel.PropertyValue propValue, PrimaryKeyResolvingMap pkMap) { if (propValue == null) throw new ArgumentNullException("propValue"); var retVal = new dataModel.PropertyValue(); pkMap.AddPair(propValue, retVal); retVal.InjectFrom(propValue); retVal.Name = propValue.PropertyName; retVal.KeyValue = propValue.ValueId; retVal.Locale = propValue.LanguageCode; retVal.ValueType = (int)propValue.ValueType; SetPropertyValue(retVal, propValue.ValueType, propValue.Value.ToString()); return retVal; }
public coreModel.DynamicContentItem CreateContent(coreModel.DynamicContentItem content) { var pkMap = new PrimaryKeyResolvingMap(); var entity = content.ToDataModel(pkMap); using (var repository = _repositoryFactory()) { repository.Add(entity); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } _dynamicPropertyService.SaveDynamicPropertyValues(content); var retVal = GetContentItemById(entity.Id); return retVal; }
public ShoppingCart Create(ShoppingCart cart) { var pkMap = new PrimaryKeyResolvingMap(); //Do business logic on temporary order object _eventPublisher.Publish(new CartChangeEvent(Platform.Core.Common.EntryState.Added, null, cart)); var entity = cart.ToDataModel(pkMap); ShoppingCart retVal = null; using (var repository = _repositoryFactory()) { repository.Add(entity); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } retVal = GetById(entity.Id); return retVal; }
public coreModel.Category Create(coreModel.Category category) { if (category == null) throw new ArgumentNullException("category"); var pkMap = new PrimaryKeyResolvingMap(); var dbCategory = category.ToDataModel(pkMap); using (var repository = _catalogRepositoryFactory()) { repository.Add(dbCategory); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } //Need add seo separately _commerceService.UpsertSeoForObjects(new[] { category }); return GetById(dbCategory.Id, Domain.Catalog.Model.CategoryResponseGroup.Info); }
public virtual MemberDataEntity FromMember(Member member, PrimaryKeyResolvingMap pkMap) { if (member == null) throw new ArgumentNullException("member"); this.InjectFrom(member); if (member.Phones != null) { this.Phones = new ObservableCollection<PhoneDataEntity>(member.Phones.Select(x => new PhoneDataEntity { Number = x, MemberId = member.Id })); } if (member.Emails != null) { this.Emails = new ObservableCollection<EmailDataEntity>(member.Emails.Select(x => new EmailDataEntity { Address = x, MemberId = member.Id })); } if (member.Addresses != null) { this.Addresses = new ObservableCollection<AddressDataEntity>(member.Addresses.Select(x => new AddressDataEntity().FromAddress(x))); foreach (var address in this.Addresses) { address.MemberId = member.Id; } } if (member.Notes != null) { this.Notes = new ObservableCollection<NoteDataEntity>(member.Notes.Select(x => new NoteDataEntity().FromNote(x))); foreach (var note in this.Notes) { note.MemberId = member.Id; } } return this; }
public static PaymentInEntity ToDataModel(this PaymentIn paymentIn, CustomerOrderEntity orderEntity, PrimaryKeyResolvingMap pkMap) { if (paymentIn == null) throw new ArgumentNullException("paymentIn"); var retVal = new PaymentInEntity(); pkMap.AddPair(paymentIn, retVal); retVal.InjectFrom(paymentIn); retVal.Currency = paymentIn.Currency.ToString(); retVal.Status = paymentIn.PaymentStatus.ToString(); if (paymentIn.BillingAddress != null) { retVal.Addresses = new ObservableCollection<AddressEntity>(new AddressEntity[] { paymentIn.BillingAddress.ToDataModel() }); } return retVal; }
public override MemberDataEntity FromMember(Member member, PrimaryKeyResolvingMap pkMap) { var organization = member as Organization; pkMap.AddPair(organization, this); if (organization.ParentId != null) { this.MemberRelations = new ObservableCollection<MemberRelationDataEntity>(); var memberRelation = new MemberRelationDataEntity { AncestorId = organization.ParentId, DescendantId = organization.Id, AncestorSequence = 1 }; this.MemberRelations.Add(memberRelation); } //Call base converter return base.FromMember(member, pkMap); }
public void Create(coreModel.Category[] categories) { if (categories == null) throw new ArgumentNullException("categories"); var pkMap = new PrimaryKeyResolvingMap(); var dbCategories = categories.Select(x => x.ToDataModel(pkMap)); using (var repository = _catalogRepositoryFactory()) { foreach (var dbCategory in dbCategories) { repository.Add(dbCategory); } CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } //Need add seo separately _commerceService.UpsertSeoForObjects(categories); }
public virtual CustomerOrder Create(CustomerOrder order) { EnsureThatAllOperationsHaveNumber(order); _eventPublisher.Publish(new OrderChangeEvent(EntryState.Added, order, order)); var pkMap = new PrimaryKeyResolvingMap(); var entity = order.ToDataModel(pkMap); using (var repository = _repositoryFactory()) { repository.Add(entity); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } _dynamicPropertyService.SaveDynamicPropertyValues(order); var retVal = GetById(entity.Id, CustomerOrderResponseGroup.Full); return retVal; }
public static LineItemEntity ToDataModel(this LineItem lineItem, PrimaryKeyResolvingMap pkMap) { if (lineItem == null) throw new ArgumentNullException("lineItem"); var retVal = new LineItemEntity(); pkMap.AddPair(lineItem, retVal); retVal.InjectFrom(lineItem); retVal.Currency = lineItem.Currency.ToString(); if(lineItem.Discount != null) { retVal.Discounts = new ObservableCollection<DiscountEntity>(new DiscountEntity[] { lineItem.Discount.ToDataModel() }); } if(lineItem.TaxDetails != null) { retVal.TaxDetails = new ObservableCollection<TaxDetailEntity>(); retVal.TaxDetails.AddRange(lineItem.TaxDetails.Select(x=>x.ToDataModel())); } return retVal; }