public void UpdateResourceState(int resourceId, int stateId) { if (resourceId == 0) { return; } using (var w = WorkspaceFactory.Create()) { var csid = w.Last <ResourceStateValue>(x => x.ResoruceId == resourceId); if (csid == null || csid.StateId != stateId) { var v = new ResourceStateValue { ResoruceId = resourceId, Date = DateTime.Now, StateId = stateId }; w.Add(v); w.CommitChanges(); } } }
private void ImportTableResources(ResourceType tableTemplate, int defaultStateId) { var fileName = string.Format("{0}/Imports/table{1}.txt", LocalSettings.AppPath, "_" + LocalSettings.CurrentLanguage); if (!File.Exists(fileName)) { fileName = string.Format("{0}/Imports/table.txt", LocalSettings.AppPath); } if (!File.Exists(fileName)) { return; } var lines = File.ReadAllLines(fileName); var items = BatchCreateResourcesWithTemplate(lines, _workspace, tableTemplate).ToList(); items.ForEach(_workspace.Add); _workspace.CommitChanges(); var screen = new ResourceScreen { Name = "All Tables", ColumnCount = 7, ResourceTypeId = tableTemplate.Id }; screen.ResourceScreenMaps.Add(new ResourceScreenMap()); _workspace.Add(screen); foreach (var resource in items) { resource.ResourceTypeId = tableTemplate.Id; screen.AddScreenItem(new ResourceScreenItem { Name = resource.Name, ResourceId = resource.Id }); var state = new ResourceStateValue { Date = DateTime.Now, ResoruceId = resource.Id, StateId = defaultStateId }; _workspace.Add(state); } _workspace.CommitChanges(); }