/// <summary> /// Converts a PSDK Skill Level object to its CTI eqivalent. /// </summary> /// <param name="skill"></param> /// <returns>An <see cref="AgentSkillLevel"/> object equivalent to the provided PSDK object.</returns> internal static AgentSkillLevel ToSkillLevel(this CfgSkillLevel skill) => new AgentSkillLevel { SkillDbid = skill.GetSkillDBID().Value, Level = skill.Level };
internal static OutputValues AddUpdateSkillToAgent(string operationType, string userName, string skillName, Int32 skillLevel) { OutputValues output = new OutputValues(); try { CfgPersonQuery queryPerson = new CfgPersonQuery(); queryPerson.UserName = userName; queryPerson.TenantDbid = _configContainer.TenantDbId; CfgPerson person = _configContainer.ConfServiceObject.RetrieveObject <CfgPerson>(queryPerson); if (operationType == "Add") { if (person != null) { ICollection <CfgSkillLevel> agentSkills = person.AgentInfo.SkillLevels; bool flag = false; foreach (CfgSkillLevel checkSkill in agentSkills) { if (checkSkill.Skill.Name == skillName) { flag = true; break; } } if (!flag) { CfgSkillQuery querySkill = new CfgSkillQuery(); querySkill.TenantDbid = _configContainer.TenantDbId; querySkill.Name = skillName; CfgSkill skill = _configContainer.ConfServiceObject.RetrieveObject <CfgSkill>(querySkill); CfgSkillLevel skillToAdd = new CfgSkillLevel(_configContainer.ConfServiceObject, person); skillToAdd.Skill = skill; skillToAdd.Level = Convert.ToInt32(skillLevel); person.AgentInfo.SkillLevels.Add(skillToAdd); person.Save(); } } } else if (operationType == "Edit") { if (person != null) { ICollection <CfgSkillLevel> agentSkills = person.AgentInfo.SkillLevels; foreach (CfgSkillLevel editingSkill in agentSkills) { if (editingSkill.Skill.Name == skillName) { editingSkill.Level = Convert.ToInt32(skillLevel); person.Save(); break; } } } } output.MessageCode = "200"; output.Message = "Skill " + operationType + "ed Successfully."; person = _configContainer.ConfServiceObject.RetrieveObject <CfgPerson>(queryPerson); if (person != null) { //Update the skill level to MySkills if (person.AgentInfo.SkillLevels != null && person.AgentInfo.SkillLevels.Count > 0) { Datacontext.GetInstance().MySkills.Clear(); foreach (CfgSkillLevel skill in person.AgentInfo.SkillLevels) { Datacontext.GetInstance().MySkills.Add(new Agent.Interaction.Desktop.Helpers.MySkills(skill.Skill.Name.ToString(), skill.Level)); } } else { Datacontext.GetInstance().MySkills.Clear(); } } } catch (Exception commonException) { output.MessageCode = "2001"; output.Message = (commonException.InnerException == null ? commonException.Message : commonException.InnerException.Message); } return(output); }