public async Task <IpMasterViewModel> GetIpAddressById(long Id)
        {
            var IpAddress = _ipMasterRepository.GetById(Id);

            if (IpAddress == null)
            {
                return(null);
            }

            var currentIpAddress = new IpMasterViewModel
            {
                Id          = IpAddress.Id,
                UserId      = IpAddress.UserId,
                IpAddress   = IpAddress.IpAddress,
                IsEnable    = IpAddress.IsEnable,
                IsDeleted   = IpAddress.IsDeleted,
                CreatedDate = IpAddress.CreatedDate,
                CreatedBy   = IpAddress.CreatedBy,
                UpdatedDate = IpAddress.UpdatedDate,
                UpdatedBy   = IpAddress.UpdatedBy,
                Status      = 0,
            };

            return(currentIpAddress);
        }
        public async Task <long> AddIpAddress(IpMasterViewModel model)
        {
            var getIp = _ipMasterRepository.Table.FirstOrDefault(i => i.IpAddress == model.IpAddress && i.UserId == model.UserId && !i.IsDeleted);

            if (getIp != null)
            {
                return(getIp.Id);
            }

            var currentIpAddress = new IpMaster
            {
                UserId      = model.UserId,
                IpAddress   = model.IpAddress,
                IsEnable    = true,
                IsDeleted   = false,
                CreatedDate = DateTime.UtcNow,
                CreatedBy   = model.UserId,
                Status      = 0,
                IpAliasName = model.IpAliasName
            };

            _ipMasterRepository.Insert(currentIpAddress);
            //_dbContext.SaveChanges();

            return(currentIpAddress.Id);
        }
        public async Task <long> DesableIpAddress(IpMasterViewModel model)
        {
            var IpAddress = _ipMasterRepository.Table.FirstOrDefault(i => i.IpAddress == model.IpAddress && i.UserId == model.UserId && !i.IsDeleted);

            if (IpAddress != null)
            {              // Status False
                IpAddress.SetAsIsDisabletatus();
                _ipMasterRepository.Update(IpAddress);
                //_dbContext.SaveChanges();
                return(IpAddress.Id);
            }
            return(0);
        }
        public async Task <long> UpdateIpAddress(IpMasterViewModel model)
        {
            var IpAddress = _ipMasterRepository.Table.FirstOrDefault(i => i.IpAddress == model.IpAddress && i.UserId == model.UserId && !i.IsDeleted);

            if (IpAddress != null)
            {
                IpAddress.IpAddress   = model.IpAddress;
                IpAddress.IpAliasName = model.IpAliasName;
                IpAddress.UpdatedBy   = IpAddress.UserId;
                IpAddress.UpdatedDate = DateTime.UtcNow;


                _ipMasterRepository.Update(IpAddress);
                return(IpAddress.Id);
                //_dbContext.SaveChanges();
            }
            else
            {
                return(0);
            }
        }
        public async Task <long> DeleteIpAddress(IpMasterViewModel model)
        {
            var IpAddress = _ipMasterRepository.Table.FirstOrDefault(i => i.IpAddress == model.IpAddress && i.UserId == model.UserId && !i.IsDeleted);

            if (IpAddress != null)
            {
                //var currentIpAddress = new IpMaster
                //{
                //    Id = IpAddress.Id,
                //    UserId = IpAddress.UserId,
                //    //IpAddress = IpAddress.IpAddress,
                //    //IsEnable = IpAddress.IsEnable,
                //    IsDeleted = true,
                //    UpdatedDate = DateTime.UtcNow,
                //    UpdatedBy = IpAddress.UserId
                //};
                IpAddress.SetAsIpDeletetatus();
                _ipMasterRepository.Update(IpAddress);
                //_dbContext.SaveChanges();
                return(IpAddress.Id);
            }
            return(0);
        }