title: Controller Check if Agent Name is already created
body: <p>I would like to add logic to check if the agent name is already created and alert the user. I created this IQueryable SearchAgents which takes in a string query and I was going to add it to the controller but I am not sure if this is the correct way.</p>
  
  <blockquote>
    <p>Is this the correct path for validating an agent is already in the system?</p>
  </blockquote>
  
  <p>AgentController</p>
  
  <pre><code>    [HttpPost]
              [ApplicationApiAuthorize("Administrator, ContentManager")]
              public IHttpActionResult CreateAgent([FromBody]AgentModel agentModel)
              {
                  LogHelper.Info($"Creating agent {agentModel.Name}");
  //Search if Agent name is in the system
              var AgentId = AgentsDataService.SearchAgents.Select(a =&gt; new AgentModel {Name = agentModel.Name }).ToList();
  
                  var agentEntity = new Agent();
                  Mapper.DynamicMap(agentModel, agentEntity);
  
                  var agentInformationEntities = Mapper.Map&lt;IEnumerable&lt;AgentInformation&gt;&gt;(agentModel.AgentInformations);
                  agentEntity.AgentInformations = new EntitySet&lt;AgentInformation&gt;();
                  agentEntity.AgentInformations.AddRange(agentInformationEntities);
  
                  var operationResult = AgentsDataService.InsertAgent(agentEntity);                        
  
                  var result = Ok(new
                  {
                      Value = Mapper.Map&lt;AgentModel&gt;(operationResult)
                  });
  
                  return result;
              }
  </code></pre>
  
  <p>AgentDataService</p>
  
  <pre><code>public IQueryable&lt;Agent&gt; SearchAgents(string query)
      {
          return GetAllAgents().Where(a =&gt; a.Name.Contains(query)).OrderBy(a =&gt; a.Name);
      }
  </code></pre>