public Admin Add(Admin entity)
        {
            if (entity.AdminId == null || entity.Password == null || entity.AdminId.Length == 0 || entity.Password.Length == 0)
            {
                throw new Exception("Identifier and Password cannot be empty");
            }

            try
            {
                if (_context.Admin.FirstOrDefault(x => x.AdminId == entity.AdminId) == null)
                {
                    var newAdmin = _context.Admin.Add(new Admin()
                    {
                        AdminId  = entity.AdminId,
                        Password = GetMD5Hash(entity.Password)
                    });

                    _context.SaveChanges();
                    return(newAdmin);
                }
                else
                {
                    throw new Exception("Admin Identifier already exists.");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public virtual User Add(User entity)
        {
            try
            {
                if (_context.User.FirstOrDefault(x => x.UserId == entity.UserId) == null)
                {
                    var user = _context.User.Add(entity);

                    _context.SaveChanges();
                    return(user);
                }
                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public virtual Device Add(Device entity)
        {
            try
            {
                if (entity.DeviceType == null && entity.DeviceTypeId == 0)
                {
                    throw new Exception("Device.TypeId doesn't exist.");
                }

                var device = _context.Device.Add(entity);
                _context.SaveChanges();

                return(device);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public virtual DeviceType Add(DeviceType entity)
 {
     try
     {
         if (_context.DeviceType.FirstOrDefault(x => x.Type == entity.Type) == null)
         {
             var deviceType = _context.DeviceType.Add(new DeviceType()
             {
                 Type = entity.Type, Unit = entity.Unit
             });
             _context.SaveChanges();
             return(deviceType);
         }
     }
     catch (Exception)
     {
         throw;
     }
     throw new Exception("DeviceType.Type already exists.");
 }