private int CopyStoreAndPageDesingAndSettings(int copyStoreId, string name, string domain, int newStoreId) { var store = StoreRepository.GetStore(copyStoreId); var storeCopy = GeneralHelper.DataContractSerialization(store); storeCopy.Id = 0; storeCopy.Name = name; storeCopy.Domain = domain; storeCopy.GoogleDriveFolder = domain; StoreRepository.Add(storeCopy); StoreRepository.Save(); newStoreId = storeCopy.Id; try { var settingsStore = SettingRepository.GetStoreSettings(copyStoreId); foreach (var settingStore in settingsStore) { var s = GeneralHelper.DataContractSerialization(settingStore); s.Id = 0; s.StoreId = newStoreId; SettingRepository.Add(s); } SettingRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } return(newStoreId); }
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); } }