title: When to use Ivalidatable object and when to use service methods to validate my post request
body: <p>I am working on an asp.net mvc web application, and we have to check if the entered IP &amp; Mac addresses already exists. Currently I am checking this by writing the following service methods inside my POST Create &amp; Edit action methods as follow:-</p>
  
  <pre><code>bool ipunique = repository.ISiPUnique(sj.NetworkInfo.IPADDRESS, sj.Server. ServerID);
  bool macunique = repository.ISmACUnique(sj.NetworkInfo.MACADDRESS, sj.Server. ServerID);
  
  if (((sj.IsIPUnique == true) &amp;&amp; !ipunique)
              {
  
  ModelState.AddModelError("NetworkInfo.IPAddress", "Error occurred. The Same IP is already assigned.");
  
              }
  if ((sj.IsMACUnique == true) &amp;&amp; (!macunique))
              {
  
  ModelState.AddModelError("NetworkInfo.MACAddress", "Error occurred. The Same MAC Address is already assigned.");
  
              }
  </code></pre>
  
  <p>where the sj.IsIPUnique is a checkbox which indicates if the uniqness check should be done or not, and the above  calls the following reporsitory method:-</p>
  
  <pre><code>public bool ISiPUnique(string ip, int? id=0) 
  {
  var result = tms.TechnologyIPs.Where(a =&gt;  (a.TechnologyID != id.Value || a.TechnologyID == null)  &amp;&amp; a.IPAddress.ToUpper() == ip.ToUpper());
  return (result.Count() == 0);
  }
  </code></pre>
  
  <p>But should I keep my code as is or it is better to do this uniqueness check inside an ivalidatable object instead of having service methods ?</p>