public Task OnGetAsync() { var catalog = _catalogService.GetObject(z => true, z => z.Id, OrderingType.Descending); CatalogDto = _catalogService.Mapper.Map <CatalogDto>(catalog); return(Task.CompletedTask); }
public bool Delete(int id) { using (UnitOfWork unitOfWork = new UnitOfWork()) { SubType result = unitOfWork.SubTypeRepository.GetById(id); if (result == null) { return(false); } if (result.Title.Equals("Unsorted")) { return(true); } TorrentService torrentService = new TorrentService(); List <TorrentDto> torrents = torrentService.GetAllBySubTypeWithDeleted(id).ToList(); CatalogDto unsortedC = catalogService.GetAllWithTitle("Unsorted").FirstOrDefault(); SubTypeDto unsortedS = GetAllWithTitle(unsortedC.Id, "Unsorted").FirstOrDefault(); foreach (var item in torrents) { item.Catalog = unsortedC; item.SybType = unsortedS; torrentService.Update(item); } unitOfWork.SubTypeRepository.Delete(result); return(unitOfWork.Save()); } }
public bool Create(CatalogDto catalogDto) { using (UnitOfWork unitOfWork = new UnitOfWork()) { var catalog = new Catalog() { Id = catalogDto.Id, IsDeleted = false, DeletedOn = catalogDto.DeletedOn, Title = catalogDto.Title, TorrentNum = 0, CreatedOn = DateTime.Now, CreatorId = catalogDto.Creator.Id }; if (catalog.Title.Equals("Unsorted")) { return(true); } unitOfWork.CatalogRepository.Create(catalog); return(unitOfWork.Save()); } }
/// <summary> /// Handles the SaveChanges event of the EditSaveControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e) { // Validate form if (!this.Page.IsValid) { e.RunScript = false; return; } CatalogDto catalog = null; if (Parameters["CatalogId"] != null) { catalog = CatalogContext.Current.GetCatalogDto(Int32.Parse(Parameters["CatalogId"].ToString())); } else { catalog = new CatalogDto(); } IDictionary context = new ListDictionary(); context.Add("Catalog", catalog); ViewControl.SaveChanges(context); int catalogId = catalog.Catalog[0].CatalogId; if (catalog.HasChanges()) { CatalogContext.Current.SaveCatalog(catalog); } }
public void Search_JoinQuery() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName); foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode) { CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = true; pars.CatalogNames.Add(catalogName); pars.CatalogNodes.Add(node.Code); pars.JoinType = "inner join"; pars.Language = "en-us"; pars.JoinSourceTable = "CatalogEntry"; pars.JoinTargetQuery = "(select distinct ObjectId, DisplayName from CatalogEntryEx) CatalogEntryEx"; pars.JoinSourceTableKey = "CatalogEntryId"; pars.JoinTargetTableKey = "CatalogEntryEx.ObjectId"; pars.OrderByClause = "CatalogEntryEx.DisplayName"; Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); } } }
public Catalog(CatalogDto catalogDto) { Name = catalogDto.Name; ParentId = catalogDto.ParentId; AddTime = DateTime.Now; this.LastUpdateTime = AddTime; }
public bool Create(TorrentDto torrentDto) { using (UnitOfWork unitOfWork = new UnitOfWork()) { var torrent = new Torrent() { Id = torrentDto.Id, IsDeleted = false, DeletedOn = torrentDto.DeletedOn, Title = torrentDto.Title, Description = torrentDto.Description, TimesDownloaded = 0, UploadedOn = DateTime.Now, UploaderId = torrentDto.Uploader.Id, CatalogId = torrentDto.Catalog.Id, SubTypeId = torrentDto.SybType.Id }; CatalogDto catalog = catalogService.GetById(torrent.CatalogId); catalog.TorrentNum += 1; if (!catalogService.Update(catalog)) { return(false); } unitOfWork.TorrentRepository.Create(torrent); return(unitOfWork.Save()); } }
public void Search_BrowseEntries() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName); foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode) { CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = true; pars.CatalogNames.Add(catalogName); pars.CatalogNodes.Add(node.Code); Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); } } }
public void CatalogSystem_UnitTest_SearchEntries() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); // Search phrase arbitrary pars.FreeTextSearchPhrase = "policy"; // Set language pars.Language = "en-us"; pars.CatalogNames.Add(catalogName); Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); // Meaningless assert - to be replaced with appropriate assert once the problem with search is figured out Assert.IsTrue(entries.TotalResults == entries.TotalResults); Console.WriteLine("Number of entries matching \"{0}\" in the {1} catalog: {2}", pars.FreeTextSearchPhrase, catalogName, entries.TotalResults); } //Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> /// Finds the catalog id. /// </summary> /// <param name="catalogName">Name of the catalog.</param> /// <returns></returns> int findCatalogId(string catalogName) { CatalogDto dto = CatalogContext.Current.GetCatalogDto(); CatalogDto.CatalogRow row = null; int index = -1; try { foreach (CatalogDto.CatalogRow node in dto.Catalog) { if (node.Name.Equals(catalogName)) { index = row.CatalogId; break; } } } catch (Exception e) { Console.Error.Write(e.Message); } return(index); }
public static int CreateCatalog(string catalogName) { var catalogDto = new CatalogDto(); var newCatalogRow = catalogDto.Catalog.NewCatalogRow(); newCatalogRow.Name = catalogName; newCatalogRow.StartDate = DateTime.Now; newCatalogRow.EndDate = DateTime.Now.AddYears(2); newCatalogRow.IsActive = true; newCatalogRow.SortOrder = 0; newCatalogRow.ApplicationId = AppContext.Current.ApplicationId; newCatalogRow.Created = DateTime.Now; newCatalogRow.Modified = DateTime.Now; // hardcoded for test: newCatalogRow.IsPrimary = false; newCatalogRow.DefaultCurrency = "eur"; newCatalogRow.WeightBase = "kgs"; newCatalogRow.DefaultLanguage = "en"; catalogDto.Catalog.AddCatalogRow(newCatalogRow); AddCatalogLanguage(catalogDto, catalogDto.Catalog[0], "en"); AddCatalogLanguage(catalogDto, catalogDto.Catalog[0], "sv"); CatalogContext.Current.SaveCatalog(catalogDto); return(newCatalogRow.CatalogId); }
public async Task <bool> IsNameExistAsync(CatalogDto objCatalogDto) { var entity = Mapper.Map <Catalog>(objCatalogDto); var result = await this.catalogRepository.IsNameExistAsync(entity); return(result); }
public async Task <IActionResult> PutAsync(string id, [FromBody] CatalogDto catalogDto) { if (!this.ModelState.IsValid) { var errors = string.Join( " | ", this.ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage)); return(this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Error, errors, this.ModelState))); } if (!Guid.TryParse(id, out var catalogId)) { return(this.Ok( ApiResponse.SetResponse(ApiResponseStatus.Error, $"{id} is not a valid Guid", string.Empty))); } var updateCatalog = await this.catalogService.GetAsync(catalogId); if (updateCatalog == null) { return(this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Error, "Catalog not found", string.Empty))); } if (await this.catalogService.IsNameExistAsync(catalogDto)) { return(this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Error, "Catalog already exist", string.Empty))); } await this.catalogService.UpdateAsync(catalogDto); return(this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Ok, "Catalog updated successfully", catalogDto))); }
private static void AddCatalogLanguage(CatalogDto workingDto, CatalogDto.CatalogRow catalogRow, string languageCode) { CatalogDto.CatalogLanguageRow languageRow = workingDto.CatalogLanguage.NewCatalogLanguageRow(); languageRow.LanguageCode = languageCode; languageRow.CatalogId = catalogRow.CatalogId; workingDto.CatalogLanguage.AddCatalogLanguageRow(languageRow); }
/// <summary> /// Gets the total records. /// </summary> /// <returns></returns> private int GetTotalRecords() { int numRecords = 0; ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = false; pars.CatalogNames.Add(catalogName); options.RecordsToRetrieve = 1; options.StartingRecord = 0; int totalCount = 0; CatalogEntryDto entryDto = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount); numRecords += totalCount; } return(numRecords); }
/// <summary> /// Binds the catalogs list. /// </summary> private void BindCatalogsList() { CatalogDto dto = CatalogContext.Current.GetCatalogDto(); ListCatalogs.DataSource = dto.Catalog.Rows; ListCatalogs.DataBind(); }
public async Task <ActionResult> Put([FromBody] CatalogDto catalog) { if (catalog == null) { return(Ok()); } try { Catalog _catalog = _mapper.Map <Catalog>(catalog); if (_catalog == null) { return(BadRequest()); } _catalogUnit.CatalogABCRepository.Update(_catalog); await _catalogUnit.SaveChangesAsync(); catalog = _mapper.Map <CatalogDto>(_catalog); return(Ok(catalog)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public bool Update(CatalogDto catalogDto) { using (UnitOfWork unitOfWork = new UnitOfWork()) { var result = unitOfWork.CatalogRepository.GetById(catalogDto.Id); if (result == null) { return(false); } if (catalogDto.Title.Equals("Unsorted")) { return(true); } result.Id = catalogDto.Id; result.IsDeleted = catalogDto.IsDeleted; result.DeletedOn = catalogDto.DeletedOn; result.Title = catalogDto.Title; result.TorrentNum = catalogDto.TorrentNum; result.CreatedOn = catalogDto.CreatedOn; result.CreatorId = catalogDto.Creator.Id; unitOfWork.CatalogRepository.Update(result); return(unitOfWork.Save()); } }
public async Task CreateCatalogAsync(CatalogDto catalogDto) { Catalog catalog = _mapper.Map <Catalog>(catalogDto); _repository.Add(catalog); await _context.SaveChangesAsync(); }
public async Task <ActionResult> Get(string id) { Guid _id = new Guid(); if (!Guid.TryParse(id, out _id)) { return(Ok()); } try { Catalog d = await _catalogUnit.CatalogRepository.GetByID(_id); if (d == null) { return(Ok()); } CatalogDto catalogs = _mapper.Map <CatalogDto>(d); return(Ok(catalogs)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
protected void PrimeCacheImpl() { ICatalogSystem catalog = ServiceLocator.Current.GetInstance <ICatalogSystem>(); IContentRepository repository = ServiceLocator.Current.GetInstance <IContentRepository>(); ReferenceConverter referenceConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>(); CatalogContentLoader contentLoader = ServiceLocator.Current.GetInstance <CatalogContentLoader>(); // Get all catalogs CatalogDto catalogDto = catalog.GetCatalogDto(); _log.Debug("Found {0} catalogs. Start iterating.", catalogDto.Catalog.Count); foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog) { _log.Debug("Loading all categories for catalog {0} ({1})", catalogRow.Name, catalogRow.CatalogId); // Get all Categories on first level CatalogNodes nodes = catalog.GetCatalogNodes(catalogRow.CatalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo)); _log.Debug("Loaded {0} categories using ICatalogSystem", nodes.CatalogNode.Count()); // Get them as content too foreach (CatalogNode node in nodes.CatalogNode) { ContentReference nodeReference = referenceConverter.GetContentLink(node.CatalogNodeId, CatalogContentType.CatalogNode, 0); NodeContent content = repository.Get <EPiServer.Commerce.Catalog.ContentTypes.NodeContent>(nodeReference); _log.Debug("Loded Category Content: {0}", content.Name); WalkCategoryTree(content, repository, contentLoader, catalog, referenceConverter); } } }
/// <summary> /// Raises the catalog updating event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="Mediachase.Commerce.Catalog.Events.CatalogEventArgs"/> instance containing the event data.</param> public void RaiseCatalogUpdatingEvent(CatalogDto sender, CatalogEventArgs args) { if (CatalogUpdating != null) { CatalogUpdating(sender, args); } }
public bool FakeDelete(int id) { using (UnitOfWork unitOfWork = new UnitOfWork()) { Torrent result = unitOfWork.TorrentRepository.GetById(id); if (result == null) { return(false); } CatalogDto catalog = catalogService.GetById(result.CatalogId); catalog.TorrentNum -= 1; if (!catalogService.Update(catalog)) { return(false); } result.IsDeleted = true; result.DeletedOn = DateTime.Now; unitOfWork.TorrentRepository.Update(result); return(unitOfWork.Save()); } }
public async Task <IActionResult> Get() { var stopWatch = new Stopwatch(); stopWatch.Start(); // temp var products = await this._productService.GetProducts(); var stock = await this._stockService.GetStock(); var catalog = new List <CatalogDto>(); products.ForEach(p => { var catalogItem = new CatalogDto() { Id = p.Id, Name = p.Name, Src = p.Src, Stock = stock?.FirstOrDefault(s => s.Id == p.Id)?.Stock ?? 0, }; catalog.Add(catalogItem); }); stopWatch.Stop(); this._logger.LogError($"Catalog get request elapsed: {stopWatch.Elapsed}"); this._telemetry.TrackRequest("Catalog get", DateTimeOffset.UtcNow, stopWatch.Elapsed, "200", true); this._telemetry.Flush(); return(this.Ok(catalog)); }
public static CatalogModel ToCatalogModel(this CatalogDto catalogDto, string url = null) { var catalogModel = new CatalogModel { Title = catalogDto.Title }; if (!string.IsNullOrEmpty(catalogDto.SubTitle)) { var desc = catalogDto.SubTitle; for (var i = 0; i < desc.Length; ++i) { if (desc[i].Equals('\n') || desc[i].Equals('\t') || desc[i].Equals(' ')) { continue; } desc = desc.Substring(i); break; } catalogModel.Description = desc; } catalogModel.IconLocalPath = "DesignBookCover.jpg"; // is for test. Remove or change when some stub for opds catalog will be ready. if (url != null) { catalogModel.Url = url; } else { var selfLink = catalogDto.Links.SingleOrDefault(l => l.Rel.Equals("self")); if (selfLink != null) { catalogModel.Url = selfLink.Href; } } var searchLink = catalogDto.Links.SingleOrDefault(l => "search".Equals(l.Rel) && !string.IsNullOrEmpty(l.Href) && OPEN_SEARCH_LINK_TYPE.Equals(l.Type)); if (searchLink != null) { Uri searchDescriptionUri; if (Uri.TryCreate(new Uri(catalogModel.Url, UriKind.RelativeOrAbsolute), searchLink.Href, out searchDescriptionUri)) { catalogModel.OpenSearchDescriptionUrl = searchDescriptionUri.ToString(); } else { catalogModel.OpenSearchDescriptionUrl = GetValidUrl(searchLink.Href, catalogModel.Url); } return(catalogModel); } searchLink = catalogDto.Links.SingleOrDefault(l => "search".Equals(l.Rel)); if (searchLink != null) { catalogModel.SearchUrl = GetValidUrl(ValidateSearchUrlTemplate(searchLink.Href), catalogModel.Url); } return(catalogModel); }
/// <summary> /// Loads the catalogs. /// </summary> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iNumItems">The i num items.</param> /// <param name="sFilter">The s filter.</param> private void LoadCatalogs(int iStartIndex, int iNumItems, string sFilter) { CatalogDto dto = CatalogContext.Current.GetCatalogDto(); CatalogFilter.Items.Clear(); CatalogFilter.DataSource = dto; CatalogFilter.DataBind(); }
public static ValidationResult Validate(this CatalogDto dto) { if (string.IsNullOrWhiteSpace(dto.Name)) { return(new ValidationResult(NameIsEmptyErrorMessage)); } return(new ValidationResult()); }
public async Task <CatalogDto> UpdateCatalogAsync(CatalogDto catalogDto) { Catalog catalog = _mapper.Map <Catalog>(catalogDto); _repository.Update(catalog); await _context.SaveChangesAsync(); return(catalogDto); }
public void PrintAllCatalogs() { CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog) { Console.WriteLine(catalogRow.Name); } }
public IActionResult Put([FromRoute] int id, [FromBody] CatalogDto catalog) { return(new JsonVoidResult { Errors = null, StatusCode = HttpStatusCode.OK, Message = null }); }
/// <summary> /// Get existing language and page name /// </summary> /// <param name="key">Key</param> /// <param name="catalog">Catalog</param> /// <param name="pageLink">Page Link</param> /// <param name="languageSelector">Language selector</param> /// <param name="nodeType">Node type</param> /// <param name="pageName">Page name to return</param> /// <param name="languageBranchId"></param> /// <returns></returns> private static IList<string> GetExistingLanguage(IDictionary<string, string> key, CatalogDto.CatalogRow catalog, PageReference pageLink, ILanguageSelector languageSelector, NodeType nodeType, out string pageName, out string languageBranchId) { var context = new LanguageSelectorContext(pageLink); languageSelector.SetInitializedLanguageBranch(context); languageBranchId = context.MasterLanguageBranch; if (!string.IsNullOrEmpty(context.SelectedLanguage)) { languageBranchId = context.SelectedLanguage; } if (string.IsNullOrEmpty(languageBranchId)) { var langSelector = languageSelector as LanguageSelector; if (langSelector != null) languageBranchId = langSelector.LanguageBranch; } if (!string.IsNullOrEmpty(languageBranchId)) { languageBranchId = languageBranchId.ToUpperInvariant(); } var enabledLanguages = LanguageBranch.ListEnabled().Select(l => l.LanguageID); // get existing language from mediachase var existingLanguage = new List<string>(); if (!string.IsNullOrEmpty(catalog.DefaultLanguage) && enabledLanguages.Contains(catalog.DefaultLanguage, StringComparer.OrdinalIgnoreCase)) { existingLanguage.Add(catalog.DefaultLanguage.ToUpperInvariant()); } catalog.GetCatalogLanguageRows().ToList().ForEach(row => { if (!string.IsNullOrEmpty(row.LanguageCode) && !existingLanguage.Contains(row.LanguageCode, StringComparer.OrdinalIgnoreCase) && enabledLanguages.Contains(row.LanguageCode, StringComparer.OrdinalIgnoreCase)) { existingLanguage.Add(row.LanguageCode.ToUpperInvariant()); } }); pageName = key[CatalogName]; string results = string.Empty; switch (nodeType) { case NodeType.CatalogEntry: results = GetEntryPageName(key, existingLanguage, languageBranchId, catalog); if (results.Length > 0) { pageName = results; } break; case NodeType.CatalogNode: results = GetNodePageName(key, existingLanguage, languageBranchId, catalog); if (results.Length > 0) { pageName = results; } break; } return existingLanguage; }
/// <summary> /// Get entry page name by language and add exisiting language to list /// </summary> /// <param name="key">The key.</param> /// <param name="existingLanguages">The existing languages.</param> /// <param name="langCode">The lang code.</param> /// <param name="catalog">The catalog.</param> /// <returns></returns> private static string GetEntryPageName(IDictionary<string, string> key, List<string> existingLanguages, string langCode, CatalogDto.CatalogRow catalog) { var entry = LookUpEntry(Convert.ToInt32(key[NodeId], CultureInfo.InvariantCulture)); var seoRows = entry.GetCatalogItemSeoRows(); if (seoRows != null && seoRows.Count() > 0) { var seoInfo = seoRows.FirstOrDefault(seo => string.Equals(seo.LanguageCode, langCode, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(seo.Uri) && existingLanguages.Contains(seo.LanguageCode, StringComparer.OrdinalIgnoreCase)) ?? seoRows.FirstOrDefault(seo => string.Equals(seo.LanguageCode, catalog.DefaultLanguage, StringComparison.OrdinalIgnoreCase)); string name = seoInfo != null && !seoInfo.IsTitleNull() && !string.IsNullOrEmpty(seoInfo.Title) ? seoInfo.Title : entry.Name; return name; } return string.Empty; }
/// <summary> /// Get catalog node page name by language and add exisiting language to list /// </summary> /// <param name="key">The key.</param> /// <param name="existingLanguages">The existing languages.</param> /// <param name="langCode">The lang code.</param> /// <param name="catalog">The catalog.</param> /// <returns></returns> private static string GetNodePageName(IDictionary<string, string> key, List<string> existingLanguages, string langCode, CatalogDto.CatalogRow catalog) { var node = LookupCatalogNode(key[NodeCode]); var nodeSeoRows = node.GetCatalogItemSeoRows(); if (nodeSeoRows != null && nodeSeoRows.Count() > 0) { var seoInfo = nodeSeoRows.FirstOrDefault(seo => string.Equals(seo.LanguageCode, langCode, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(seo.Uri) && existingLanguages.Contains(seo.LanguageCode, StringComparer.OrdinalIgnoreCase)) ?? nodeSeoRows.FirstOrDefault(seo => string.Equals(seo.LanguageCode, catalog.DefaultLanguage, StringComparison.OrdinalIgnoreCase)); string name = (seoInfo != null && !seoInfo.IsTitleNull() && !string.IsNullOrEmpty(seoInfo.Title) ? seoInfo.Title : node.Name); return name; } return string.Empty; }
/// <summary> /// Returns parent key /// </summary> /// <param name="parameter">The parameter.</param> /// <param name="nodeId">The node id.</param> /// <param name="catalog">The catalog.</param> /// <returns></returns> private static string GetParentKey(IDictionary<string, string> parameter, int nodeId, CatalogDto.CatalogRow catalog) { var nodeType = (NodeType)Enum.Parse(typeof(NodeType), parameter[CatalogNodeType]); if (nodeType == NodeType.Catalog) return string.Empty; string parentKey = string.Empty; var parentNode = LookupCatalogNode(parameter[ParentNodeCode]); if (parentNode == null) //catalog { return MappedPPDB.BuildKey("0", catalog.Name, "-1", catalog.CatalogId, NodeType.Catalog, catalog.Name, catalog.Name); } else { if (parentNode.ParentNodeId == 0) // grant parent is catalog { parentKey = MappedPPDB.BuildKey(nodeId, parentNode.Name, catalog.CatalogId, parameter[CatalogId], NodeType.CatalogNode, parentNode.Code, catalog.Name); } else { var grantParent = LookupCatalogNode(parentNode.ParentNodeId); parentKey = MappedPPDB.BuildKey(nodeId, parentNode.Name, parentNode.ParentNodeId, parameter[CatalogId], NodeType.CatalogNode, parentNode.Code, grantParent.Code); } } return parentKey; }
public static int CreateCatalog(string catalogName) { var catalogDto = new CatalogDto(); var newCatalogRow = catalogDto.Catalog.NewCatalogRow(); newCatalogRow.Name = catalogName; newCatalogRow.StartDate = DateTime.Now; newCatalogRow.EndDate = DateTime.Now.AddYears(2); newCatalogRow.IsActive = true; newCatalogRow.SortOrder = 0; newCatalogRow.ApplicationId = AppContext.Current.ApplicationId; newCatalogRow.Created = DateTime.Now; newCatalogRow.Modified = DateTime.Now; // hardcoded for test: newCatalogRow.IsPrimary = false; newCatalogRow.DefaultCurrency = "eur"; newCatalogRow.WeightBase = "kgs"; newCatalogRow.DefaultLanguage = "en"; catalogDto.Catalog.AddCatalogRow(newCatalogRow); AddCatalogLanguage(catalogDto, catalogDto.Catalog[0], "en"); AddCatalogLanguage(catalogDto, catalogDto.Catalog[0], "sv"); CatalogContext.Current.SaveCatalog(catalogDto); return newCatalogRow.CatalogId; }
private static void AddCatalogLanguage(CatalogDto workingDto, CatalogDto.CatalogRow catalogRow, string languageCode) { CatalogDto.CatalogLanguageRow languageRow = workingDto.CatalogLanguage.NewCatalogLanguageRow(); languageRow.LanguageCode = languageCode; languageRow.CatalogId = catalogRow.CatalogId; workingDto.CatalogLanguage.AddCatalogLanguageRow(languageRow); }