public int GetProductsNumber(Catalogue catalog) { var catalogRepository = GetCatalogRepository(catalog); using (IDocumentSession session = catalogRepository.OpenSession()) { var productNumber = session.Query<ProductItem>().Where(p => p.CatalogueId == catalog.Id).Count(); return productNumber; } }
/// <summary> /// Delete all product related to the catalogue, and the catalogue itself /// </summary> /// <param name="catalogueId"></param> /// <returns>Number of products deleted</returns> public int DeleteCatalog(Catalogue catalog) { var deletedProducts = DeleteProducts(catalog); using (IDocumentSession session = DocumentRepository.OpenSession()) { session.Delete(catalog.Id); session.SaveChanges(); } return deletedProducts; }
public ActionResult Create(Catalogue catalogue) { var documentRepository = new DocumentRepository(); catalogue.Created = DateTime.Now; catalogue.Updated = DateTime.Now; catalogue.Status = CatalogStatus.DRAFT; catalogue.Id = string.Empty; documentRepository.Save(catalogue); return RedirectToAction("Detail", "Merchant", new { Id = catalogue.MerchantId }); }
public DTO.ImportResult DraftImport(Stream originalFile, Catalogue catalogue) { var documentRepository = new DocumentRepository(); var merchant = documentRepository.Load<Merchant>(catalogue.MerchantId); var XmlDoc = XDocument.Load(new StreamReader(originalFile)); var importResult = new DTO.ImportResult(); XNamespace g = "http://base.google.com/ns/1.0"; foreach (var item in XmlDoc.Element("rss").Element("channel").Elements("item")) { try { var productItem = new ProductItem() { Age = TranslateAge(item.Element(g + "age_group").Value), Availability = item.Element(g + "availability").Value, Brand = item.Element(g + "brand").Value, CatalogueId = catalogue.Id, Color = item.Element(g + "color").Value, Condition = item.Element(g + "condition").Value, Created = DateTime.Now, Description = item.Element("description").Value, Gender = TranslateGender(item.Element(g + "gender").Value), GoogleProductCategory = item.Element(g + "google_product_category").Value, GoogleTaxonomy = GoogleTaxonomy.GetTaxonomy(int.Parse(item.Element(g + "google_product_category").Value), catalogue.CountryCode), AdditionalImageLinks = item.Elements(g + "additional_image_link").Select(el => el.Value).ToList(), Id = string.Format("{0}__{1}", catalogue.Id, item.Element(g + "id").Value), MainImageLink = item.Element(g + "image_link").Value, Material = item.Element(g + "material").Value, Merchant = merchant, Pricing = new PricingInfo { Price = ExtractPriceValue(item.Element(g + "price").Value), SalePrice = ExtractPriceValue(item.Element(g + "sale_price").Value) }, ProductGroup = item.Element(g + "item_group_id").Value, ProductLink = item.Element("link").Value, MobileProductLink = item.Element("mobile_link").Value, Shipping = new ShippingInfo() { Price = item.Element(g + "shipping").Element(g + "price").Value, Service = item.Element(g + "shipping").Element(g + "service").Value }, SizeInfo = new SizeInfo { Size = item.Element(g + "size").Value, SizeSystem = item.Element(g + "size_system").Value, SizeType = item.Element(g + "size_type").Value }, SKU = item.Element(g + "mpn").Value, Title = item.Element("title").Value, Updated = DateTime.Now }; var stagingDocumentRepository = new StagingDocumentRepository(); stagingDocumentRepository.Save(productItem); importResult.Success++; } catch (Exception ex) { importResult.Failure++; importResult.FailureDetails.Add(ex.Message); } } //TODO: salvare l'importResult anche sul documento del catalogo in staging return importResult; }
public int DeleteProducts(Catalogue catalog) { var catalogRepository = GetCatalogRepository(catalog); var productsNumber = GetProductsNumber(catalog); var indexName = new ProductItems_ByCatalogueId().IndexName; var operation = catalogRepository.GetStore().DatabaseCommands.DeleteByIndex( indexName, new IndexQuery { Query = string.Format("CatalogueId: {0}", catalog.Id) }, new BulkOperationOptions { AllowStale = true }); var result = operation.WaitForCompletion(); return productsNumber; }
private ICatalogRepository GetCatalogRepository(Catalogue catalog) { ICatalogRepository catalogRepository = null; if (catalog.Status == CatalogStatus.LIVE) catalogRepository = new CatalogDocumentRepository(); else catalogRepository = new StagingDocumentRepository(); return catalogRepository; }
public IList<ProductItem> GetProducts(Catalogue catalog, ProductsFilter filter) { if (filter == null) throw new FilterNotSetException(); var catalogRepository = GetCatalogRepository(catalog); using (IDocumentSession session = catalogRepository.OpenSession()) { var products = session.Query<ProductItem>() .Where(p => p.CatalogueId == catalog.Id) .Skip(filter.MaxPageSize * (filter.PageNumber -1)) .Take(filter.MaxPageSize) .ToList(); return products; } }