public static void upload(string filepath) { var data = Helpers.LoadCSV(filepath); // Map columns var mapper = new CSVMapper { DataTable = data }; if (mapper.map("name", new[] { "NAME", "ID", "DISPLAYNAME", "SKILL" }) == -1) { throw new ArgumentException("Name column not found", "name"); } mapper.map("workgroups", new[] { "WORKGROUP", "WORKGROUPS", "GROUP", "GROUPS" }); mapper.map("users", new[] { "USER", "USERS", "AGENT", "AGENTS" }); var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession)); foreach (DataRow row in data.Rows) { SkillConfiguration skill = null; var name = row.Field <string>(mapper["name"]); if (string.IsNullOrWhiteSpace(name)) { continue; } if (!SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name)) { skill = configurations.CreateObject(); skill.SetConfigurationId(name); skill.SetDisplayName(name); } else { skill = SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name); skill.PrepareForEdit(); } if (mapper["workgroups"] > -1) { skill.WorkgroupAssignments.Value.Clear(); Helpers.ParseManySkillSettings(row.Field <string>(mapper["workgroups"])).ForEach(x => skill.WorkgroupAssignments.Value.Add(x)); } if (mapper["users"] > -1) { skill.UserAssignments.Value.Clear(); Helpers.ParseManySkillSettings(row.Field <string>(mapper["users"])).ForEach(x => skill.UserAssignments.Value.Add(x)); } skill.Commit(); } _SkillConfigurations = null; // So the list is fetched again }
public static Skill find_or_create(string name) { if (!SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name)) { try { var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession)); var skill = configurations.CreateObject(); skill.SetConfigurationId(name); skill.SetDisplayName(name); skill.Commit(); _SkillConfigurations = null; // So the list is fetched again } catch (Exception e) { throw e; } } return(new Skill(SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name))); }
public static Skill create(string name) { if (SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name)) { throw new DuplicateKeyException(name, string.Format("Skill {0} already exists", name)); } try { var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession)); var skill = configurations.CreateObject(); skill.SetConfigurationId(name); skill.SetDisplayName(name); skill.Commit(); _SkillConfigurations = null; // So the list is fetched again } catch (Exception e) { throw e; } return(new Skill(SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name))); }
public static void upload(string filepath) { var data = Helpers.LoadCSV(filepath); // Map columns var mapper = new CSVMapper { DataTable = data }; if (mapper.map("name", new[] { "NAME", "ID", "DISPLAYNAME", "SKILL" }) == -1) throw new ArgumentException("Name column not found", "name"); mapper.map("workgroups", new[] { "WORKGROUP", "WORKGROUPS", "GROUP", "GROUPS" }); mapper.map("users", new[] { "USER", "USERS", "AGENT", "AGENTS" }); var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession)); foreach (DataRow row in data.Rows) { SkillConfiguration skill = null; var name = row.Field<string>(mapper["name"]); if (string.IsNullOrWhiteSpace(name)) continue; if (! SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name)) { skill = configurations.CreateObject(); skill.SetConfigurationId(name); skill.SetDisplayName(name); } else { skill = SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name); skill.PrepareForEdit(); } if (mapper["workgroups"] > -1) { skill.WorkgroupAssignments.Value.Clear(); Helpers.ParseManySkillSettings(row.Field<string>(mapper["workgroups"])).ForEach(x => skill.WorkgroupAssignments.Value.Add(x)); } if (mapper["users"] > -1) { skill.UserAssignments.Value.Clear(); Helpers.ParseManySkillSettings(row.Field<string>(mapper["users"])).ForEach(x => skill.UserAssignments.Value.Add(x)); } skill.Commit(); } _SkillConfigurations = null; // So the list is fetched again }
public static Skill find_or_create(string name) { if (! SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name)) { try { var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession)); var skill = configurations.CreateObject(); skill.SetConfigurationId(name); skill.SetDisplayName(name); skill.Commit(); _SkillConfigurations = null; // So the list is fetched again } catch(Exception e) { throw e; } } return new Skill(SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name)); }
public static Skill create(string name) { if (SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name)) { throw new DuplicateKeyException(name, string.Format("Skill {0} already exists", name)); } try { var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession)); var skill = configurations.CreateObject(); skill.SetConfigurationId(name); skill.SetDisplayName(name); skill.Commit(); _SkillConfigurations = null; // So the list is fetched again } catch(Exception e) { throw e; } return new Skill(SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name)); }