public static webModel.FulfillmentCenter ToWebModel(this coreModel.FulfillmentCenter center) { var retVal = new webModel.FulfillmentCenter(); retVal.InjectFrom(center); return(retVal); }
public coreModel.FulfillmentCenter UpsertFulfillmentCenter(coreModel.FulfillmentCenter center) { if (center == null) { throw new ArgumentNullException("center"); } using (var repository = _repositoryFactory()) { var sourceEntry = center.ToDataModel(); var targetEntry = repository.FulfillmentCenters.FirstOrDefault(x => x.Id == center.Id); if (targetEntry == null) { repository.Add(sourceEntry); } else { sourceEntry.Patch(targetEntry); } CommitChanges(repository); var result = repository.FulfillmentCenters .First(x => x.Id == sourceEntry.Id) .ToCoreModel(); return(result); } }
public static coreModel.FulfillmentCenter ToCoreModel(this dataModel.FulfillmentCenter center) { var retVal = new coreModel.FulfillmentCenter(); retVal.InjectFrom(center); return(retVal); }
public coreModel.FulfillmentCenter UpsertFulfillmentCenter(coreModel.FulfillmentCenter center) { if (center == null) { throw new ArgumentNullException(nameof(center)); } var pkMap = new PrimaryKeyResolvingMap(); using (var repository = _repositoryFactory()) { var sourceEntry = AbstractTypeFactory <dataModel.FulfillmentCenter> .TryCreateInstance().FromModel(center, pkMap); var targetEntry = repository.FulfillmentCenters.FirstOrDefault(x => x.Id == center.Id); if (targetEntry == null) { repository.Add(sourceEntry); } else { sourceEntry.Patch(targetEntry); } CommitChanges(repository); pkMap.ResolvePrimaryKeys(); var result = repository.FulfillmentCenters .First(x => x.Id == sourceEntry.Id) .ToModel(AbstractTypeFactory <coreModel.FulfillmentCenter> .TryCreateInstance()); return(result); } }
public static coreModel.FulfillmentCenter ToCoreModel(this webModel.FulfillmentCenter fulfillment) { var retVal = new coreModel.FulfillmentCenter(); retVal.InjectFrom(fulfillment); return retVal; }
public static coreModel.FulfillmentCenter ToCoreModel(this webModel.FulfillmentCenter fulfillment) { var retVal = new coreModel.FulfillmentCenter(); retVal.InjectFrom(fulfillment); return(retVal); }
public virtual coreModel.FulfillmentCenter ToModel(coreModel.FulfillmentCenter center) { center.City = City; center.CountryCode = CountryCode; center.CountryName = CountryName; center.DaytimePhoneNumber = DaytimePhoneNumber; center.Description = Description; center.Id = Id; center.Line1 = Line1; center.Line2 = Line2; center.Name = Name; center.PostalCode = PostalCode; center.StateProvince = StateProvince; return(center); }
public virtual dataModel.FulfillmentCenter FromModel(coreModel.FulfillmentCenter center, PrimaryKeyResolvingMap pkMap) { pkMap.AddPair(this, center); City = center.City; CountryCode = center.CountryCode; CountryName = center.CountryName; DaytimePhoneNumber = center.DaytimePhoneNumber; Description = center.Description; Id = center.Id; Line1 = center.Line1; Line2 = center.Line2; Name = center.Name; PostalCode = center.PostalCode; StateProvince = center.StateProvince; return(this); }
public IHttpActionResult UpdateFulfillmentCenter(coreModel.FulfillmentCenter center) { var retVal = _commerceService.UpsertFulfillmentCenter(center); return(Ok(retVal)); }
private void PopulateInventory(FulfillmentCenter center, IEnumerable<CatalogItem> items) { if (center == null || items == null || !items.Any()) return; var inventories = _inventoryService.GetProductsInventoryInfos(items.Select(x=>x.Id).ToArray()).ToList(); foreach (var catalogItem in items) { var productInventory = inventories.FirstOrDefault(x => x.ProductId == catalogItem.Id && x.FulfillmentCenterId == center.Id); if (productInventory != null) catalogItem.Inventory = productInventory.ToWebModel(); } }
private void PopulateInventory(FulfillmentCenter center, IEnumerable<CatalogProduct> products) { if (center == null || products == null || !products.Any()) return; var inventories = _inventoryService.GetProductsInventoryInfos(products.Select(x => x.Id).ToArray()).ToList(); foreach (var product in products) { var productInventory = inventories.FirstOrDefault(x => x.ProductId == product.Id && x.FulfillmentCenterId == center.Id); if (productInventory != null) product.Inventories = new List<InventoryInfo> { productInventory }; } }
public static coreModel.FulfillmentCenter ToCoreModel(this dataModel.FulfillmentCenter center) { var retVal = new coreModel.FulfillmentCenter(); retVal.InjectFrom(center); return retVal; }
private void SaveProduct(coreModel.Catalog catalog, FulfillmentCenter defaultFulfillmentCenter, CsvProduct csvProduct) { var defaultLanguge = catalog.DefaultLanguage != null ? catalog.DefaultLanguage.LanguageCode : "EN-US"; coreModel.CatalogProduct alreadyExistProduct = null; //For new product try to find them by code if (csvProduct.IsTransient() && !String.IsNullOrEmpty(csvProduct.Code)) { var criteria = new SearchCriteria { CatalogId = catalog.Id, CategoryId = csvProduct.CategoryId, Code = csvProduct.Code, ResponseGroup = ResponseGroup.WithProducts | ResponseGroup.WithVariations }; var result = _searchService.Search(criteria); alreadyExistProduct = result.Products.FirstOrDefault(); csvProduct.Id = alreadyExistProduct != null ? alreadyExistProduct.Id : csvProduct.Id; } else if (!csvProduct.IsTransient()) { //If id specified need check that product really exist alreadyExistProduct = _productService.GetById(csvProduct.Id, ItemResponseGroup.ItemInfo); } var isNewProduct = alreadyExistProduct == null; csvProduct.CatalogId = catalog.Id; if (String.IsNullOrEmpty(csvProduct.Code)) { csvProduct.Code = _skuGenerator.GenerateSku(csvProduct); } //Set a parent relations if (csvProduct.MainProductId == null && csvProduct.MainProduct != null) { csvProduct.MainProductId = csvProduct.MainProduct.Id; } csvProduct.EditorialReview.LanguageCode = defaultLanguge; csvProduct.SeoInfo.LanguageCode = defaultLanguge; csvProduct.SeoInfo.SemanticUrl = String.IsNullOrEmpty(csvProduct.SeoInfo.SemanticUrl) ? csvProduct.Code : csvProduct.SeoInfo.SemanticUrl; var properties = !String.IsNullOrEmpty(csvProduct.CategoryId) ? _propertyService.GetCategoryProperties(csvProduct.CategoryId) : _propertyService.GetCatalogProperties(csvProduct.CatalogId); if (csvProduct.PropertyValues != null) { //Try to fill properties meta information for values foreach (var propertyValue in csvProduct.PropertyValues) { if (propertyValue.Value != null) { var property = properties.FirstOrDefault(x => String.Equals(x.Name, propertyValue.PropertyName)); if (property != null) { propertyValue.ValueType = property.ValueType; if (property.Dictionary) { property = _propertyService.GetById(property.Id); var dicValue = property.DictionaryValues.FirstOrDefault(x => String.Equals(x.Value, propertyValue.Value)); propertyValue.ValueId = dicValue != null ? dicValue.Id : null; } } } } } if (!isNewProduct) { _productService.Update(new coreModel.CatalogProduct[] { csvProduct }); } else { var newProduct = _productService.Create(csvProduct); csvProduct.Id = newProduct.Id; } //Create price in default price list if (csvProduct.Price.EffectiveValue > 0) { csvProduct.Price.ProductId = csvProduct.Id; if (csvProduct.Price.IsTransient() || _pricingService.GetPriceById(csvProduct.Price.Id) == null) { _pricingService.CreatePrice(csvProduct.Price); } else { _pricingService.UpdatePrices(new Price[] { csvProduct.Price }); } } //Create inventory csvProduct.Inventory.ProductId = csvProduct.Id; csvProduct.Inventory.FulfillmentCenterId = csvProduct.Inventory.FulfillmentCenterId ?? defaultFulfillmentCenter.Id; _inventoryService.UpsertInventory(csvProduct.Inventory); }