Writing Service method Versus writing an Ivalidatable object

64 Views Asked by At

I am working on an asp.net mvc web application, and we have to check if the user enter an IP And/OR Mac address which already exists. Currently I am checking this by writing the following service methods inside my POST Create & Edit action methods as follow:-

bool ipunique = repository.ISiPUnique(sj.NetworkInfo.IPADDRESS, sj.Server. ServerID);
bool macunique = repository.ISmACUnique(sj.NetworkInfo.MACADDRESS, sj.Server. ServerID);

if (((sj.IsIPUnique == true) && !ipunique)
            {

ModelState.AddModelError("NetworkInfo.IPAddress", "Error occurred. The Same IP is already assigned.");

            }
if ((sj.IsMACUnique == true) && (!macunique))
            {

ModelState.AddModelError("NetworkInfo.MACAddress", "Error occurred. The Same MAC Address is already assigned.");

            }

Where both sj.IsIPUnique & sj.IsMACUnique are check boxes where the user will check this if he wants to check for the uniqueness before adding or editing the record, and if he leave the check boxes unchecked then no uniqueness validation will occur.

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 ?

0

There are 0 best solutions below