Exemplo n.º 1
0
        public CIDRSettingModel Add(CIDRSettingModel model)
        {
            if (model == null)
            {
                throw new MobileException("非法的CIDRSettingModel参数,model 不能为空.");
            }
            model.ID = Guid.NewGuid().ToString();
            cidrsetting item = new cidrsetting
            {
                ID = model.ID,
                CreatedBy = model.CreatedBy,
                CreatedDate = DateTime.Now,
                LastUpdatedBy = model.CreatedBy,
                LastUpdatedDate = DateTime.Now,
                IPStart = model.IPStart,
                IPStartNum = IPHelper.IPToNumber(model.IPStart),
                IPEnd = model.IPEnd,
                IPEndNum = IPHelper.IPToNumber(model.IPEnd),
                TCPPort = model.TCPPort,
                TTLThreshold = model.TTLFaZhi,
                TCPThreshold = model.TCPFaZhi,
                TTLExceptionKeys = model.TTLExceptionKeys
            };

            using (var dbContext = new DataEntities())
            {
                dbContext.cidrsettings.AddObject(item);
                dbContext.SaveChanges();
            }

            return model;
        }
Exemplo n.º 2
0
        public List<RouteData> AddRoutDatas(List<RouteData> routeDatas)
        {
            if (routeDatas == null || routeDatas.Count == 0)
            {
                return routeDatas;
            }

            using (var dbContext = new DataEntities())
            {
                foreach (var item in routeDatas)
                {
                    if (item == null)
                    {
                        continue;
                    }

                    item.CreatedDate = DateTime.Now;
                    item.LastUpdatedDate = DateTime.Now;
                    dbContext.RouteDatas.AddObject(item);
                }

                dbContext.SaveChanges();
            }

            return routeDatas;
        }
Exemplo n.º 3
0
        public void AddIPScanResults(List<IPScanResult> results)
        {
            if (results == null || results.Count == 0)
            {
                throw new MobileException("非法的results参数,results 不能为空.");
            }

            using (var dbContext = new DataEntities())
            {
                foreach (var item in results)
                {
                    var dbItem = new ipscanresults
                    {
                        CreatedBy = item.CreatedBy,
                        CreatedDate = DateTime.Now,
                        LastUpdatedBy = item.LastUpdatedBy,
                        LastUpdatedDate = DateTime.Now,
                        IP = item.IP,
                        TCPTime = item.TCPResponseTime,
                        TCPValidation = item.TCPValidationResult,
                        TTLValidation = item.TTLValidationResult
                    };

                    dbContext.ipscanresults.AddObject(dbItem);
                }
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 4
0
 public void DeleteTokens(string userName)
 {
     using (var dbContext = new DataEntities())
     {
         foreach (var item in dbContext.Tokens.Where(t => t.UserName == userName))
         {
             dbContext.DeleteObject(item);
         }
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 5
0
        public ClientIP Add(ClientIP clientIP)
        {
            clientIP.CreatedDate = DateTime.Now;
            clientIP.LastUpdatedDate = DateTime.Now;

            using (var dbContext = new DataEntities())
            {
                dbContext.ClientIPs.AddObject(clientIP);
                dbContext.SaveChanges();
            }

            return clientIP;
        }
Exemplo n.º 6
0
        public void DeleteSetting(string id)
        {
            using (var dbContext = new DataEntities())
            {
                var dbSetting = dbContext.cidrsettings.Where(c => c.ID.Equals(id, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (dbSetting != null)
                {
                    dbContext.DeleteObject(dbSetting);
                    dbContext.SaveChanges();
                }
            }
        }
Exemplo n.º 7
0
        public void DeleteUser(string userId)
        {
            using (var dbContext = new DataEntities())
            {
                var dbUser = dbContext.Users.Where(u => u.UserName.Equals(userId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (dbUser != null)
                {
                    dbContext.DeleteObject(dbUser);
                    dbContext.SaveChanges();
                }
            }
        }
Exemplo n.º 8
0
        public string NewToken(token tokenModel)
        {
            tokenModel.Token = Guid.NewGuid().ToString("N");
            tokenModel.CreatedDate = DateTime.Now;
            tokenModel.ExpiredDate = DateTime.Now.AddYears(1);

            using (var dbContext = new DataEntities())
            {
                dbContext.Tokens.AddObject(tokenModel);
                dbContext.SaveChanges();
            }

            return tokenModel.Token;
        }
Exemplo n.º 9
0
        public void Add(LoginRecord loginRecord)
        {
            if (loginRecord == null)
            {
                return;
            }

            loginRecord.LoginDate = DateTime.Now;

            using (var dbContext = new DataEntities())
            {
                dbContext.LoginRecords.AddObject(loginRecord);
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public User AddUser(User user)
        {
            if (user == null)
            {
                throw new MobileException("非法的user参数,user 不能为空.");
            }

            using (var dbContext = new DataEntities())
            {
                user.CreatedDate = DateTime.Now;
                user.LastUpdatedDate = DateTime.Now;
                dbContext.Users.AddObject(user);
                dbContext.SaveChanges();
            }

            return user;
        }
Exemplo n.º 11
0
        public void ChangePassword(string userName, string newPassword)
        {
            if (String.IsNullOrWhiteSpace(userName))
            {
                throw new Exception("参数userName不能为空。");
            }

            using (var dbContext = new DataEntities())
            {
                var dbUser = dbContext.Users.Where(u => u.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (dbUser == null)
                {
                    throw new Exception("该用户不存在!");
                }
                else
                {
                    dbUser.Password = newPassword;
                    dbContext.SaveChanges();
                }
            }
        }
Exemplo n.º 12
0
        public void UpdateSetting(CIDRSettingModel model)
        {
            if (model == null || String.IsNullOrWhiteSpace(model.ID))
            {
                throw new Exception("参数CIDRSettingModel不能为空。");
            }

            using (var dbContext = new DataEntities())
            {
                var dbSetting = dbContext.cidrsettings.Where(m => m.ID.Equals(model.ID, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (dbSetting == null)
                {
                    throw new Exception("该CIDR设置不存在!");
                }
                else
                {
                    dbSetting.LastUpdatedBy = model.LastUpdatedBy;
                    dbSetting.LastUpdatedDate = DateTime.Now;
                    dbSetting.IPStart = model.IPStart;
                    dbSetting.IPEnd = model.IPEnd;
                    dbSetting.TCPPort = model.TCPPort;
                    dbSetting.IPStartNum = IPHelper.IPToNumber(model.IPStart);
                    dbSetting.IPEndNum = IPHelper.IPToNumber(model.IPEnd);
                    dbSetting.TTLThreshold = model.TTLFaZhi;
                    dbSetting.TCPThreshold = model.TCPFaZhi;
                    dbSetting.TTLExceptionKeys = model.TTLExceptionKeys;
                    dbContext.SaveChanges();
                }
            }
        }
Exemplo n.º 13
0
        public void UpdateUser(User user)
        {
            if (user == null || String.IsNullOrWhiteSpace(user.UserName))
            {
                throw new Exception("参数userName不能为空。");
            }

            using (var dbContext = new DataEntities())
            {
                var dbUser = dbContext.Users.Where(u => u.UserName.Equals(user.UserName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (dbUser == null)
                {
                    throw new Exception("该用户不存在!");
                }
                else
                {
                    dbUser.FullName = user.FullName;
                    dbUser.Phone = user.Phone;
                    dbUser.Description = user.Description;
                    dbUser.City = user.City;
                    dbContext.SaveChanges();
                }
            }
        }