protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); switch (this.ParameterSetName) { case AddContentParameterSet: Guid newId1 = _repository.Add(Entity, Id, Attributes); if (PassThru) { WriteObject(_repository.Get(Entity, newId1, null)); } break; case AddContentByInputObjectParameterSet: Guid newId2 = _repository.Add(InputObject); if (PassThru) { WriteObject(_repository.Get(InputObject.LogicalName, newId2, null)); } break; default: break; } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); Entity newSolution = new Entity("solution") { Attributes = new AttributeCollection() }; newSolution.Attributes.Add("uniquename", Name); newSolution.Attributes.Add("friendlyname", DisplayName); newSolution.Attributes.Add("version", Version); newSolution.Attributes.Add("publisherid", new EntityReference("publisher", Publisher)); if (!string.IsNullOrWhiteSpace(Description)) { newSolution.Attributes.Add("description", Description); } Guid newSolutionId = _repository.Add(newSolution); if (PassThru) { WriteObject(_repository.Get("solution", newSolutionId)); } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); Guid[] roleIds = Roles; Guid businessUnitId = BusinessUnit ?? SecurityManagementHelper.GetDefaultBusinessUnitId(_repository); Entity newUser = new Entity("systemuser") { Attributes = new AttributeCollection() }; newUser.Attributes.Add("domainname", UserName); newUser.Attributes.Add("firstname", Firstname); newUser.Attributes.Add("lastname", Lastname); newUser.Attributes.Add("accessmode", new OptionSetValue((int)Access)); newUser.Attributes.Add("caltype", new OptionSetValue((int)License)); newUser.Attributes.Add("businessunitid", new EntityReference("businessunit", businessUnitId)); Guid newUserId = _repository.Add(newUser); SecurityManagementHelper.LinkPrincipalRoles(_repository, "systemuser", newUserId, "role", roleIds); if (PassThru) { WriteObject(_repository.Get("systemuser", newUserId)); } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); Guid[] userIds = Users; Guid businessUnitId = BusinessUnit ?? SecurityManagementHelper.GetDefaultBusinessUnitId(_repository); Entity newTeam = new Entity("team") { Attributes = new AttributeCollection() }; newTeam.Attributes.Add("name", Name); newTeam.Attributes.Add("teamtype", new OptionSetValue((int)TeamType)); newTeam.Attributes.Add("administratorid", new EntityReference("systemuser", Administrator)); newTeam.Attributes.Add("businessunitid", new EntityReference("businessunit", businessUnitId)); if (!string.IsNullOrWhiteSpace(Description)) { newTeam.Attributes.Add("description", Description); } Guid newTeamId = _repository.Add(newTeam); if (Users != null && Users.Length != 0) { SecurityManagementHelper.AddUsersToTeam(_repository, newTeamId, Users); } if (PassThru) { WriteObject(_repository.Get("team", newTeamId)); } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); int valuePrefix = new Random().Next(10000, 99999); if (OptionSetValuePrefix.HasValue) { valuePrefix = OptionSetValuePrefix.Value; } Entity newPublisher = new Entity("publisher") { Attributes = new AttributeCollection() }; newPublisher.Attributes.Add("uniquename", Name); newPublisher.Attributes.Add("friendlyname", DisplayName); newPublisher.Attributes.Add("customizationprefix", Prefix); newPublisher.Attributes.Add("customizationoptionvalueprefix", valuePrefix); if (!string.IsNullOrWhiteSpace(Description)) { newPublisher.Attributes.Add("description", Description); } Guid newPublisherId = _repository.Add(newPublisher); if (PassThru) { WriteObject(_repository.Get("publisher", newPublisherId)); } }
internal void AddDebate(dynamic newDebate) { DebateInfo debate = new DebateInfo { subject = newDebate.Subject, date_created = newDebate.Date_created, state = newDebate.State, description = newDebate.Description, }; dynamic addedDebate = _debateRepository.Add(debate); var id = addedDebate.debate_id; Content newContent = new Content { debate_id = id, round_1 = newDebate.Round_1, round_2 = newDebate.Round_2, round_3 = newDebate.Round_3, round_4 = newDebate.Round_4, round_5 = newDebate.Round_5, round_6 = newDebate.Round_6 }; _contentRepository.Add(newContent); foreach (string categ in newDebate.Category) { int categ_id = _categoryRepository.GetByName(categ).id; _categoryDebateRepository.Add(new CategoryDebate { debate_id = id, category_id = categ_id }); } _userDebateRepository.Add(new UserDebate { debate_id = id, pro_username = newDebate.Pro_username, con_username = newDebate.Con_username }); _roundStateRepository.Add(new RoundState { debate_id = id, next_round = 1, time_to_next = (AuthToken.GetNistTime() + threeDaysInMillis).ToString() }); }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); Entity newWebResource = new Entity("webresource") { Attributes = new AttributeCollection() }; newWebResource.Attributes.Add("name", Name); newWebResource.Attributes.Add("webresourcetype", new OptionSetValue(GetWebresourceTypeFromEnum(WebresourceType))); if (!string.IsNullOrWhiteSpace(DisplayName)) { newWebResource.Attributes.Add("displayname", DisplayName); } if (!string.IsNullOrWhiteSpace(Description)) { newWebResource.Attributes.Add("description", Description); } if (IsCustomizable.HasValue) { newWebResource.Attributes.Add("iscustomizable", IsCustomizable.Value); } switch (this.ParameterSetName) { case NewWebresourceFromContentParameterSet: string contentAsBase64 = Convert.ToBase64String(Content); newWebResource.Attributes.Add("content", contentAsBase64); break; case NewWebresourceFromPathParameterSet: FileContentReaderWriter fcrw = new FileContentReaderWriter(LiteralPath, _contentParameters.EncodingType, _contentParameters.UsingByteEncoding); byte[] fileAsBytes = fcrw.ReadAsBytes(); string fileContentAsBase64 = Convert.ToBase64String(fileAsBytes); newWebResource.Attributes.Add("content", fileContentAsBase64); break; default: break; } Guid newId = _repository.Add(newWebResource); if (PassThru) { WriteObject(_repository.Get("webresource", newId, null)); } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); if ((int)Claim == 0) { Claim = CrmServiceEndpointUserClaim.None; } if (Contract == CrmServiceEndpointContract.Rest && Federated.ToBool() == true) { throw new Exception("Federated mode not suppored for REST contract."); } ValidateNameUnique(_repository, Name); Guid newId = _repository.Add(GenerateCrmEntity()); if (PassThru) { WriteObject(_repository.Get("serviceendpoint", newId)); } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); Guid businessUnitId = BusinessUnit ?? SecurityManagementHelper.GetDefaultBusinessUnitId(_repository); Entity newRole = new Entity("role") { Attributes = new AttributeCollection() }; newRole.Attributes.Add("name", Name); newRole.Attributes.Add("businessunitid", new EntityReference("businessunit", businessUnitId)); Guid newRoleId = _repository.Add(newRole); if (PassThru) { WriteObject(_repository.Get("role", newRoleId)); } }
public Header Add(Guid documentId, Header header) { if (DocumentRepository.Exists(documentId)) { if (!HeaderRepository.ExistsForDocument(documentId)) { Document documentThatBelongs = DocumentRepository.GetById(documentId); documentThatBelongs.StyleClass = null; header.DocumentThatBelongs = documentThatBelongs; header.Id = Guid.NewGuid(); header.Content = new Content() { Id = Guid.NewGuid() }; if (header.StyleClass != null && !StyleClassRepository.Exists(header.StyleClass.Name)) { header.StyleClass = null; } ContentRepository.Add(header.Content); HeaderRepository.Add(header); return(header); } else { throw new ExistingHeaderException("This document already has a header."); } } else { throw new MissingDocumentException("This document is not in the database."); } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); Entity crmPluginStep = _repository.Get("sdkmessageprocessingstep", PluginStep); EntityReference crmPluginStepMessageReference = crmPluginStep.GetAttributeValue <EntityReference>("sdkmessageid"); string[] messageProperties = PluginManagementHelper.GetSdkMessagePropertyNames(crmPluginStepMessageReference.Name); if (messageProperties == null || messageProperties.Length == 0) { throw new Exception(string.Format("Steps registered on message '{0}'do not support images.", crmPluginStepMessageReference.Name)); } else if (messageProperties.Length > 1) { string messageProperty = messageProperties.SingleOrDefault(s => s.Equals(MessagePropertyName, StringComparison.InvariantCultureIgnoreCase)); if (string.IsNullOrWhiteSpace(messageProperty)) { throw new Exception( string.Format("Message '{0}' supports multiple message properties ({1}). Include the parameter 'MessagePropertyName'.", crmPluginStepMessageReference.Name, string.Join(", ", messageProperties))); } MessagePropertyName = messageProperty; } else { MessagePropertyName = messageProperties[0]; } Guid newId = _repository.Add(GenerateCrmEntity()); if (PassThru) { WriteObject(_repository.Get("sdkmessageprocessingstepimage", newId)); } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); if (Mode == CrmPluginStepMode.Asynchronous && Stage != CrmPluginStepStage.PostOperation) { throw new Exception("Asynchronous Execution Mode requires registration in one of the Post Stages. Please change the Mode or the Stage."); } if (!string.IsNullOrWhiteSpace(SecureConfig) && (Deployment == CrmPluginStepDeployment.OfflineOnly || Deployment == CrmPluginStepDeployment.Both)) { throw new Exception("Secure Configuration is not supported for Steps deployed Offline."); } Entity crmEventSource = RetrieveEventSource(EventSource); if (crmEventSource == null) { throw new Exception(string.Format("No Plugin or ServiceEndpoint found with Id '{0}'.", EventSource)); } SdkMessageFilter = RetrieveMessageFilter(Message, PrimaryEntity, SecondaryEntity); if (SdkMessageFilter == null) { throw new Exception(string.Format("No supported Steps found for '{0}' on entities {1} and {2}.", Message, PrimaryEntity, SecondaryEntity)); } else { SdkMessage = SdkMessageFilter.GetAttributeValue <EntityReference>("sdkmessageid"); Message = SdkMessage.Name; PrimaryEntity = SdkMessageFilter.GetAttributeValue <string>("primaryobjecttypecode"); SecondaryEntity = SdkMessageFilter.GetAttributeValue <string>("secondaryobjecttypecode"); } int filterAvailability = SdkMessageFilter.GetAttributeValue <int>("availability"); if (!IsDeploymentSupported(filterAvailability, Deployment)) { throw new Exception(string.Format("The Step must be deployed '{0}'.", Enum.GetName(typeof(CrmPluginStepDeployment), filterAvailability))); } if (IsServiceEndpoint && Mode == CrmPluginStepMode.Synchronous) { throw new Exception("Only asynchronous Steps are supported for Service Endpoint plug-ins."); } string generatedDescription = string.Empty; if (IsServiceEndpoint) { generatedDescription = PluginManagementHelper.GenerateStepDescription(crmEventSource.GetAttributeValue <string>("name"), Message, PrimaryEntity, SecondaryEntity); } else { generatedDescription = PluginManagementHelper.GenerateStepDescription(crmEventSource.GetAttributeValue <string>("typename"), Message, PrimaryEntity, SecondaryEntity); } if (string.IsNullOrWhiteSpace(Name)) { Name = generatedDescription; } if (string.IsNullOrWhiteSpace(Description)) { Description = generatedDescription; } Guid secureConfigId = Guid.Empty; if (!string.IsNullOrWhiteSpace(SecureConfig)) { secureConfigId = _repository.Add("sdkmessageprocessingstepsecureconfig", Guid.Empty, new System.Collections.Hashtable() { { "secureconfig", SecureConfig } }); } Guid newId = _repository.Add(GenerateCrmEntity(secureConfigId)); if (PassThru) { WriteObject(_repository.Get("sdkmessageprocessingstep", newId)); } }
/// <summary> /// InMemoryデータベース用のユニットテストデータを作成する /// </summary> void ImportInitializeData(int threadId, SimpleInjector.Container container) { var @dbc = (AppDbContext)container.GetInstance <IAppDbContext>(); // Category var repo_Category = new CategoryRepository(@dbc); repo_Category.Add(new Category { Id = 2, Name = "テストカテゴリA" }); repo_Category.Add(new Category { Id = 3, Name = "テストカテゴリA2" }); repo_Category.Add(new Category { Id = 4, Name = "テストカテゴリA3" }); // Label var repo_Label = new LabelRepository(@dbc); repo_Label.Add(new Label { Id = 1, Name = "テストラベル" }); repo_Label.Add(new Label { Id = 2, Name = "テストラベル_2", Category = (Category)repo_Category.Load(1) }); // Content var repo_Content = new ContentRepository(@dbc); repo_Content.Add(new Content { Id = 1, Name = "Content1", IdentifyKey = "IDEN_Content1" }); repo_Content.Add(new Content { Id = 2, Name = "Content2", IdentifyKey = "IDEN_Content2", }); repo_Content.Add(new Content { Id = 3, Name = "Content3", IdentifyKey = "IDEN_Content3" }); // Workspace var repo_Workspace = new WorkspaceRepository(@dbc); var workspace1 = new Workspace { Id = 1, Name = "UT_Workspace", PhysicalPath = Path.Combine(TESTDATADIRECTORY, "PixstockSrvUT_" + threadId) }; repo_Workspace.Add(workspace1); // FileMappingInfo var repo_FileMappingInfo = new FileMappingInfoRepository(@dbc); repo_FileMappingInfo.Add(new FileMappingInfo { Id = 1, AclHash = "ABC1", Workspace = workspace1 }); @dbc.SaveChanges(); var label2 = repo_Label.Load(2L); label2.Contents.Add(new Label2Content { ContentId = 1L, Content = (Content)repo_Content.Load(1L), LabelId = 2L, Label = label2 }); @dbc.SaveChanges(); }
public ActionResult SaveOrEdit(Content content, int[] selectedFileId = null, int[] selectedLabelId = null) { try { if (ModelState.IsValid) { if (content.CategoryId == 0) { var labels = new List <LabelLine>(); var fileManagers = new List <FileManager>(); int mainImageFileManagerId = 0; if (content.Id > 0) { content = ContentRepository.GetContentWithFiles(content.Id); labels = LabelLineRepository.GetLabelLinesByItem(content.Id, ContentType); fileManagers = content.ContentFiles.Select(r => r.FileManager).ToList(); var mainImage = content.ContentFiles.FirstOrDefault(r => r.IsMainImage); if (mainImage != null) { mainImageFileManagerId = mainImage.FileManagerId; } } ViewBag.MainImageId = mainImageFileManagerId; ViewBag.SelectedLabels = labels.Select(r => r.LabelId).ToArray(); ViewBag.FileManagers = fileManagers; ModelState.AddModelError("CategoryId", "You should select category from category tree."); return(View(content)); } if (content.Id == 0) { ContentRepository.Add(content); ClearCache(content.StoreId); } else { ContentRepository.Edit(content); } ContentRepository.Save(); int contentId = content.Id; if (selectedFileId != null) { ContentFileRepository.SaveContentFiles(selectedFileId, contentId); } LabelLineRepository.SaveLabelLines(selectedLabelId, contentId, ContentType); if (IsSuperAdmin) { return(RedirectToAction("Index", new { storeId = content.StoreId, categoryId = content.CategoryId })); } else { return(RedirectToAction("Index", new { categoryId = content.CategoryId })); } } } catch (Exception ex) { Logger.Error(ex, "Unable to save changes:" + ex.StackTrace, content); //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(content)); }
private void RegisterPluginAssembly(string path) { PluginAssemblyInfo assemblyInfo = PluginManagementHelper.RetrievePluginAssemblyInfo(path); PluginManagementHelper.RefreshFromExistingAssembly(_repository, assemblyInfo); assemblyInfo.SourceType = AssemblyLocation ?? CrmAssemblySourceType.Database; assemblyInfo.IsolationMode = IsolationMode ?? CrmAssemblyIsolationMode.Sandbox; if (Description != null) { assemblyInfo.Description = Description; } if (assemblyInfo.AssemblyId != Guid.Empty && Force.ToBool() != true) { throw new Exception(string.Format("Assembly '{0}' is already registered. Use Force to overwrite the assembly.", assemblyInfo.Name)); } List <PluginTypeInfo> pluginsToRegister = GetPluginsToRegister(assemblyInfo); if (pluginsToRegister.Count == 0) { throw new Exception("No Plugins for registration."); } if (assemblyInfo.IsolationMode == CrmAssemblyIsolationMode.Sandbox && pluginsToRegister.Any(p => p.Isolatable != true)) { throw new Exception("Since some of the plug-ins cannot be isolated, the assembly cannot be marked as Isolated."); } if (string.IsNullOrWhiteSpace(assemblyInfo.PublicKeyToken) && pluginsToRegister.Any(p => p.PluginType == CrmPluginType.Plugin)) { throw new Exception("Assemblies containing Plugins must be strongly signed. Sign the Assembly using a KeyFile."); } Entity pluginAssemblyEntity = GenerateCrmEntity(assemblyInfo); Guid assemblyId = pluginAssemblyEntity.Id; if (assemblyId == Guid.Empty) { assemblyId = _repository.Add(pluginAssemblyEntity); } else { _repository.Update(pluginAssemblyEntity); } foreach (PluginTypeInfo plugin in pluginsToRegister) { Entity pluginTypeEntity = GenerateCrmEntity(assemblyId, plugin); Guid pluginTypeId = pluginTypeEntity.Id; if (pluginTypeEntity.Id == Guid.Empty) { pluginTypeId = _repository.Add(pluginTypeEntity); } else { _repository.Update(pluginTypeEntity); } if (PassThru) { WriteObject(_repository.Get("plugintype", pluginTypeId)); } } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); Entity crmPluginStep = _repository.Get("sdkmessageprocessingstep", Id); Mode = Mode ?? (CrmPluginStepMode)crmPluginStep.GetAttributeValue <OptionSetValue>("mode").Value; Stage = Stage ?? (CrmPluginStepStage)crmPluginStep.GetAttributeValue <OptionSetValue>("stage").Value; Deployment = Deployment ?? (CrmPluginStepDeployment)crmPluginStep.GetAttributeValue <OptionSetValue>("supporteddeployment").Value; if (Mode == CrmPluginStepMode.Asynchronous && Stage != CrmPluginStepStage.PostOperation) { throw new Exception("Asynchronous Execution Mode requires registration in one of the Post Stages. Please change the Mode or the Stage."); } if (!string.IsNullOrWhiteSpace(SecureConfig) && (Deployment == CrmPluginStepDeployment.OfflineOnly || Deployment == CrmPluginStepDeployment.Both)) { throw new Exception("Secure Configuration is not supported for Steps deployed Offline."); } EntityReference crmMessageFilterReference = crmPluginStep.GetAttributeValue <EntityReference>("sdkmessagefilterid"); Entity crmMessageFilter = _repository.Get(crmMessageFilterReference.LogicalName, crmMessageFilterReference.Id); int filterAvailability = crmMessageFilter.GetAttributeValue <int>("availability"); if (!IsDeploymentSupported(filterAvailability, Deployment.Value)) { throw new Exception(string.Format("The Step must be deployed '{0}'.", Enum.GetName(typeof(CrmPluginStepDeployment), filterAvailability))); } EntityReference crmEventHandlerReference = crmPluginStep.GetAttributeValue <EntityReference>("eventhandler"); if (crmEventHandlerReference.LogicalName.Equals("serviceendpoint", StringComparison.InvariantCultureIgnoreCase) && Mode == CrmPluginStepMode.Synchronous) { throw new Exception("Only asynchronous Steps are supported for Service Endpoint plug-ins."); } if (!string.IsNullOrWhiteSpace(Name)) { if (crmPluginStep.Contains("name")) { crmPluginStep.Attributes["name"] = Name; } else { crmPluginStep.Attributes.Add("name", Name); } } if (Description != null) { string description = string.IsNullOrWhiteSpace(Description) ? null : Description; if (crmPluginStep.Contains("description")) { crmPluginStep.Attributes["description"] = description; } else { crmPluginStep.Attributes.Add("description", description); } } if (UnsecureConfig != null) { string unsecureConfig = string.IsNullOrWhiteSpace(UnsecureConfig) ? null : UnsecureConfig; if (crmPluginStep.Contains("configuration")) { crmPluginStep.Attributes["configuration"] = unsecureConfig; } else { crmPluginStep.Attributes.Add("configuration", unsecureConfig); } } if (ExecutionOrder.HasValue) { if (crmPluginStep.Contains("rank")) { crmPluginStep.Attributes["rank"] = ExecutionOrder.Value; } else { crmPluginStep.Attributes.Add("rank", ExecutionOrder.Value); } } if (DeleteAsyncOperation.IsPresent) { if (crmPluginStep.Contains("asyncautodelete")) { crmPluginStep.Attributes["asyncautodelete"] = DeleteAsyncOperation.ToBool(); } else { crmPluginStep.Attributes.Add("asyncautodelete", DeleteAsyncOperation.ToBool()); } } if (User != null) { if (User.Value != Guid.Empty) { if (crmPluginStep.Contains("impersonatinguserid")) { crmPluginStep.Attributes["impersonatinguserid"] = new EntityReference("systemuser", User.Value); } else { crmPluginStep.Attributes.Add("impersonatinguserid", new EntityReference("systemuser", User.Value)); } } else { if (crmPluginStep.Contains("impersonatinguserid")) { crmPluginStep.Attributes["impersonatinguserid"] = null; } else { crmPluginStep.Attributes.Add("impersonatinguserid", null); } } } if (Attributes != null) { EntityReference crmMessageReference = crmPluginStep.GetAttributeValue <EntityReference>("sdkmessageid"); if (crmMessageReference.Name.Equals("update", StringComparison.InvariantCultureIgnoreCase)) { if (Attributes.Length != 0) { string filteringAttributes = string.Join(",", Attributes); if (crmPluginStep.Contains("filteringattributes")) { crmPluginStep.Attributes["filteringattributes"] = filteringAttributes; } else { crmPluginStep.Attributes.Add("filteringattributes", filteringAttributes); } } else { if (crmPluginStep.Contains("filteringattributes")) { crmPluginStep.Attributes["filteringattributes"] = null; } else { crmPluginStep.Attributes.Add("filteringattributes", null); } } } } crmPluginStep.Attributes["mode"] = new OptionSetValue((int)Mode); crmPluginStep.Attributes["stage"] = new OptionSetValue((int)Stage); crmPluginStep.Attributes["supporteddeployment"] = new OptionSetValue((int)Deployment); EntityReference crmSecureConfigReference = crmPluginStep.GetAttributeValue <EntityReference>("sdkmessageprocessingstepsecureconfigid"); if (SecureConfig != null) { if (!string.IsNullOrWhiteSpace(SecureConfig)) { if (crmSecureConfigReference != null) { _repository.Update(crmSecureConfigReference.LogicalName, crmSecureConfigReference.Id, new System.Collections.Hashtable() { { "secureconfig", SecureConfig } }); } else { Guid secureConfigId = _repository.Add("sdkmessageprocessingstepsecureconfig", Guid.Empty, new System.Collections.Hashtable() { { "secureconfig", SecureConfig } }); crmPluginStep.Attributes.Add("sdkmessageprocessingstepsecureconfigid", new EntityReference("sdkmessageprocessingstepsecureconfig", secureConfigId)); } } else { if (crmSecureConfigReference != null) { crmPluginStep.Attributes["sdkmessageprocessingstepsecureconfigid"] = null; } } } _repository.Update(crmPluginStep); if (SecureConfig != null && string.IsNullOrWhiteSpace(SecureConfig) && crmSecureConfigReference != null) { _repository.Delete(crmSecureConfigReference.LogicalName, crmSecureConfigReference.Id); } if (PassThru) { WriteObject(_repository.Get("sdkmessageprocessingstep", Id)); } }
private void CopyStoreData(int copyStoreId, int newStoreId) { StoreDbContext.Configuration.ProxyCreationEnabled = false; try { var items = NavigationRepository.GetNavigationsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; NavigationRepository.Add(s); } NavigationRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = LocationRepository.GetLocationsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; LocationRepository.Add(s); } LocationRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = EmailListRepository.GetStoreEmailList(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; EmailListRepository.Add(s); } EmailListRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = BrandRepository.GetBrandsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; BrandRepository.Add(s); } BrandRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = ContactRepository.GetContactsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; ContactRepository.Add(s); } ContactRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } int productCategoryId = 0; try { var items = ProductCategoryRepository.GetProductCategoriesByStoreId(copyStoreId); foreach (var productCategory in items) { var s = GeneralHelper.DataContractSerialization(productCategory); s.Id = 0; s.StoreId = newStoreId; ProductCategoryRepository.Add(s); ProductCategoryRepository.Save(); productCategoryId = s.Id; } } catch (Exception ex) { Logger.Error(ex, "ProductCategoryRepository:CopyStore"); } int blogCategoryId = 0; int newsCategoryId = 0; try { var items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.BlogsType); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; CategoryRepository.Add(s); CategoryRepository.Save(); blogCategoryId = s.Id; } items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.NewsType); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; CategoryRepository.Add(s); CategoryRepository.Save(); newsCategoryId = s.Id; } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = ProductRepository.GetProductsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.ProductCategoryId = productCategoryId; s.StoreId = newStoreId; ProductRepository.Add(s); ProductRepository.Save(); } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.BlogsType); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; s.CategoryId = blogCategoryId; ContentRepository.Add(s); ContentRepository.Save(); } items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.NewsType); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; s.CategoryId = newsCategoryId; ContentRepository.Add(s); ContentRepository.Save(); } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = LabelRepository.GetLabelsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; LabelRepository.Add(s); LabelRepository.Save(); } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = ActivityRepository.GetActivitiesByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; ActivityRepository.Add(s); ActivityRepository.Save(); } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } }