private async Task UpdateMetaInfo(PriceItem item, product product) { if (!SameMetaInfo(item, product)) { product = ProductsMapper.FillMetaInfo(item, product); if (product.on_sale == 1) { var specialPriceRule = await GetSpecialPriceRule(product); if (specialPriceRule != null) { if (specialPriceRule.reduction_type != "percentage") { throw new NotImplementedException(); } product.price = product.price / specialPriceRule.reduction; } } Log.Debug("Updating meta info. Reference: {0}", item.Reference); await _apiFactory.ProductFactory.Update(product); Log.Information("Meta info updated. Reference: {0}", item.Reference); } }
public FilterController() { _productService = new ProductService(); _carService = new CarService(); _specificationTypeService = new SpecificationTypeService(); _productsMapper = new ProductsMapper(); _carsMapper = new CarsMapper(); }
public ActionResult <Response <Products> > InsertUpdate([FromBody] Products products) { var rtn = new Response <Products>(); rtn.Item = ProductsMapper.InsertUpdate(products); rtn.Message = (products.Id != 0) ? "Producto Agregado con Exito" : "Producto Modificado con Exito"; rtn.MessageType = MessageType.OK; return(Ok(rtn)); }
public ActionResult <Response <bool> > ActiveDesactive(int productId) { var rtn = new Response <bool>(); rtn.Item = ProductsMapper.ActiveDesactive(productId); rtn.Message = "Producto Modificado con Exito"; rtn.MessageType = MessageType.OK; return(Ok(rtn)); }
private async Task <combination> CheckCombination(combination combination, Assort assort, product product) { if (combination != null && combination.reference != assort.Reference) { combination.reference = assort.Reference; await _apiFactory.CombinationFactory.Update(combination); } if (!product.associations.combinations.Exists(s => s.id == combination.id)) { product = ProductsMapper.MapCombination(product, combination); await _apiFactory.ProductFactory.Update(product); } return(combination); }
public ActionResult <Response <Products> > GetBySucursal([FromQuery] int sucursalId) { var prods = ProductsMapper.GetBySucursal(sucursalId); var rtn = new Response <Products>(); rtn.Items = prods; if (rtn.Items != null) { rtn.Message = "Productos recuperado con Exito"; rtn.MessageType = MessageType.OK; } return(Ok(rtn)); }
public void Map1Item() { // arrange IProductsMapper productsMapper = new ProductsMapper(); ASCIIEncoding codificador = new System.Text.ASCIIEncoding(); Stream stream = new MemoryStream(codificador.GetBytes( "<?xml version=\"1.0\" ?><products><product id=\"1\" name=\"IPod Nano\" unitPrice=\"129.55\" discontinued=\"false\"/></products>")); // act IEnumerable<Product> products = productsMapper.Map(stream); // assert Assert.That(products, Has.Some.Matches<Product>(p => p.Id == 1)); Assert.That(products, Has.Some.Matches<Product>(p => p.Name == "IPod Nano")); Assert.That(products, Has.Some.Matches<Product>(p => p.UnitPrice == 129.55m)); Assert.That(products, Has.Some.Matches<Product>(p => p.Discontinued == false)); }
private async Task <combination> CreateCombination(product product, Assort assort, product_option_value sizeOptionValue, product_option_value colorOptionValue, bool isDefault) { var combination = new combination { id_product = product.id, reference = assort.Reference, ean13 = assort.Ean13, associations = new AssociationsCombination(), minimal_quantity = 1, default_on = Convert.ToInt32(isDefault), }; combination.associations.product_option_values = new List <Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value>(); if (colorOptionValue != null) { combination.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = colorOptionValue.id.Value }); } if (sizeOptionValue != null) { combination.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = sizeOptionValue.id.Value }); } combination = await _apiFactory.CombinationFactory.Add(combination); product = ProductsMapper.MapCombination(product, combination); Log.Information("Combitation created. Size: {0}, Color: {1}. Product reference: {2}, Combination Reference: {3}", sizeOptionValue?.name[0].Value, colorOptionValue?.name[0].Value, product.reference, combination.reference); await _apiFactory.ProductFactory.Update(product); return(combination); }
public ModelStatistics TrainForecast(IReadOnlyList <IDataRow> data) { var mlData = ProductsMapper.MapToProductsList(data); // products var stats = ProductsMapper.CalculateProductStats(mlData); var client = new RestClient(_mlServerUrl); var request = new RestRequest(_trainForecastUrl, Method.POST); request.AddJsonBody(stats); var response = client.Execute <bool>(request); var ok = response.Data; if (!ok) { throw new Exception("something is wrong with ML engine, check it"); } // countries var countryStats = ProductsMapper.CalculateCountryStats(mlData); var client2 = new RestClient(_mlServerUrl); var request2 = new RestRequest(_trainForecastCountryUrl, Method.POST); request2.AddJsonBody(countryStats); var response2 = client2.Execute <bool>(request2); var ok2 = response2.Data; if (!ok2) { throw new Exception("something is wrong with ML engine, check it"); } return(null); }
public async Task Create(PriceItem priceItem) { if (string.IsNullOrWhiteSpace(priceItem.PhotoSmall) && (priceItem.Photos == null || !priceItem.Photos.Any())) { return; } Log.Information("Adding product {0}", priceItem.Reference); var product = ProductsMapper.Create(priceItem); var categories = await _categoryProcessor.GetCategories(priceItem); product = ProductsMapper.MapCategories(product, categories); var supplier = _apiFactory.Suppliers.First(s => s.name.Equals(priceItem.SupplierName, StringComparison.CurrentCultureIgnoreCase)); product = ProductsMapper.MapSupplier(product, supplier); var featureValue = await _featureProcessor.GetFeatureValue(priceItem.Material, _apiFactory.MaterialFeature); product = ProductsMapper.MapFeature(product, featureValue); featureValue = await _featureProcessor.GetFeatureValue(priceItem.Country, _apiFactory.CountryFeature); product = ProductsMapper.MapFeature(product, featureValue); featureValue = await _featureProcessor.GetFeatureValue(priceItem.Packing, _apiFactory.PackingFeature); product = ProductsMapper.MapFeature(product, featureValue); featureValue = await _featureProcessor.GetFeatureValue(priceItem.Length, _apiFactory.LengthFeature); product = ProductsMapper.MapFeature(product, featureValue); featureValue = await _featureProcessor.GetFeatureValue(priceItem.Diameter, _apiFactory.DiameterFeature); product = ProductsMapper.MapFeature(product, featureValue); featureValue = await _featureProcessor.GetFeatureValue(priceItem.Battery, _apiFactory.BatteryFeature); product = ProductsMapper.MapFeature(product, featureValue); var manufacturerValue = await _manufacturerProcessor.GetManufacturerValue(priceItem, product); product = ProductsMapper.MapManufacturer(product, manufacturerValue); product = ProductsMapper.FillMetaInfo(priceItem, product); // Добавление продукта product = await _apiFactory.ProductFactory.Add(product); if (priceItem.Photos == null || !priceItem.Photos.Any()) { var image = await _imageProcessor.GetImageValue(priceItem.PhotoSmall, product); product = ProductsMapper.MapImage(product, image); if (product.id_default_image == null) { Log.Information("Setting default image for product {reference}. ImageId: {imageId}", priceItem.Reference, image.id); product.id_default_image = image.id; await _apiFactory.ProductFactory.Update(product); } } else { image coverPhoto = null; foreach (var photo in priceItem.Photos) { var image = await _imageProcessor.GetImageValue(photo, product); if (coverPhoto == null) { coverPhoto = image; } product = ProductsMapper.MapImage(product, image); } if (product.id_default_image == null && coverPhoto != null) { Log.Information("Setting default image for product {reference}. ImageId: {imageId}", priceItem.Reference, coverPhoto.id); product.id_default_image = coverPhoto.id; await _apiFactory.ProductFactory.Update(product); } } if (product.associations.images == null || !product.associations.images.Any()) { Log.Warning("Unable to load product photos. Product will be deleted. Product reference: {0}", priceItem.Reference); await _apiFactory.ProductFactory.Delete(product.id.Value); Log.Debug("Product deleted. Reference: {0}", priceItem.Reference); throw new PhotoLoadException(); } await _supplierProcessor.GetProductSupplierValue(priceItem, product, supplier); await _combinationsProcessor.FillOptions(priceItem, product); await _stockProcessor.UpdateStockValue(priceItem, product); }
public ProductsController(IDataReader dataReader, ProductsMapper mapper) { _dataReader = dataReader; _mapper = mapper; }
public ActionResult <IList <ProductsStock> > GetStockBySucursal([FromQuery] int sucursalId) { var rtn = ProductsMapper.GetStockBySucursal(sucursalId); return(Ok(rtn)); }
public ActionResult <PageItems <Products> > GetToList([FromQuery] int sucursalId, [FromQuery] int PageSize, [FromQuery] int CurrentPage, [FromQuery] int rubroId = 0, [FromQuery] int subRubroId = 0) { var rtn = ProductsMapper.GetToList(sucursalId, PageSize, CurrentPage, rubroId, subRubroId); return(Ok(rtn)); }
public ProductController() { _productService = new ProductService(); _productsMapper = new ProductsMapper(); }