예제 #1
0
        public bool Add(RoleModel model)
        {
            var temp = false;

            using (var context = new db_cmaEntities())
            {
                //DOBase<tb_role> tRole = new DOBase<tb_role>(context);
                //tRole.Add(GetModel(model));
                tb_role dbmodel = new tb_role()
                {
                    Name        = model.Name,
                    Description = model.Description
                };
                context.tb_role.Add(dbmodel);
                context.SaveChanges();
                if (model.ActionList.Count() > 0)
                {
                    dbmodel.tb_action.Clear();
                    dbmodel.tb_action = context.tb_action.Where(n => model.ActionList.Contains(n.Id)).ToList();
                }
                //context.Configuration.ValidateOnSaveEnabled = false;
                temp = context.SaveChanges() > 0 ? true : false;
                //context.Configuration.ValidateOnSaveEnabled = true;
            }
            return(temp);
        }
예제 #2
0
        public bool Add(UserInfoModel model)
        {
            bool result = false;

            try
            {
                using (var context = new db_cmaEntities())
                {
                    tb_user dbmodel = new tb_user()
                    {
                        Email    = model.Email,
                        Password = model.Password,
                        RealName = model.RealName,
                        Telphone = model.Telphone,
                        Username = model.Username,
                        State    = model.State,
                    };
                    context.tb_user.Add(dbmodel);
                    context.SaveChanges();
                    //dbmodel = context.tb_user.Where(n => n.Id == dbmodel.Id).FirstOrDefault();
                    if (model.RoleList.Count > 0)
                    {
                        dbmodel.tb_role.Clear();
                        dbmodel.tb_role = context.tb_role.Where(n => model.RoleList.Contains(n.Id)).ToList();
                    }
                    result = context.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(result);
        }
예제 #3
0
 public bool Login(tb_user user)
 {
     using (var context = new db_cmaEntities())
     {
         return(context.tb_user.Where(n => n.Username == user.Username && n.Password == user.Password).FirstOrDefault() != null);
     }
 }
예제 #4
0
        public bool Delete(long id)
        {
            bool result = false;

            try
            {
                using (var context = new db_cmaEntities())
                {
                    var dbmodel = context.tb_user.First(u => u.Id == id);
                    if (dbmodel.State != 1)
                    {
                        dbmodel.State = 1;
                        context.Configuration.ValidateOnSaveEnabled = false;
                        result = context.SaveChanges() > 0;
                        context.Configuration.ValidateOnSaveEnabled = true;
                    }
                    else
                    {
                        return(true);//已删除
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(result);
        }
예제 #5
0
        public bool Delete(long id)
        {
            bool result = false;

            try
            {
                using (var context = new db_cmaEntities())
                {
                    var dbmodel = context.tb_monitoritem.First(u => u.Id == id);
                    if (dbmodel != null)
                    {
                        context.tb_monitoritem.Remove(dbmodel);
                        result = context.SaveChanges() > 0;
                    }
                    else
                    {
                        return(true);//已删除
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(result);
        }
예제 #6
0
 public IEnumerable <MessageModel> GetList()
 {
     using (var context = new db_cmaEntities())
     {
         DOBase <tb_message> tRole = new DOBase <tb_message>(context);
         return(tRole.Where(r => true).ToList().Select(n => GetModel(n)));
     }
 }
예제 #7
0
 public IEnumerable <ActionModel> GetList()
 {
     using (var context = new db_cmaEntities())
     {
         var dbModelList = context.tb_action.ToList();
         return(dbModelList.Select(n => GetModel(n)));
     }
 }
예제 #8
0
 public MonitorItemDBModel Get(int id)
 {
     using (var context = new db_cmaEntities())
     {
         var tbItem = context.tb_monitoritem.Where(n => n.Id == id).FirstOrDefault();
         MonitorItemDBModel itemList = GetDBMonitorItemModel(tbItem);
         return(itemList);
     }
 }
예제 #9
0
 public IEnumerable <CollectorDBModel> GetList()
 {
     using (var context = new db_cmaEntities())
     {
         var tbItemList = context.tb_collector.ToList();
         IEnumerable <CollectorDBModel> itemList = tbItemList.Select(n => GetDBCollectorModel(n));
         return(itemList);
     }
 }
예제 #10
0
 public IEnumerable <UserInfoModel> GetList()
 {
     using (var context = new db_cmaEntities())
     {
         //var dbModelList = context.tb_user.ToList();
         var dbModelList = context.tb_user.Where(u => u.State == 0).ToList();
         return(dbModelList.Select(n => GetModel(n)));
     }
 }
예제 #11
0
 internal IEnumerable <ActionModel> GetListFromRole(long id)
 {
     using (var context = new db_cmaEntities())
     {
         //var dbModelList = context.tb_action.Where(n=>n.).ToList();
         //return dbModelList.Select(n => GetModel(n));
     }
     return(null);
 }
예제 #12
0
 public IEnumerable <MonitorItemDBModel> GetList()
 {
     using (var context = new db_cmaEntities())
     {
         var tbItemList = context.tb_monitoritem.ToList();
         IEnumerable <MonitorItemDBModel> itemList = tbItemList.Select(n => GetDBMonitorItemModel(n));
         return(itemList);
     }
 }
예제 #13
0
        public MessageModel Get(long id)
        {
            MessageModel result = null;

            using (var context = new db_cmaEntities())
            {
                DOBase <tb_message> tRole = new DOBase <tb_message>(context);
                result = GetModel(tRole.GetModel(id));
            }
            return(result);
        }
예제 #14
0
        /// <summary>
        /// 检查用户名是否已存在
        /// </summary>
        /// <param name="model"></param>
        /// <returns>fasle--用户名可用 无重复</returns>
        /// <returns>true --用户名不可用 有重复</returns>
        public bool IsExit(UserInfoModel model)
        {
            bool result = false;

            using (var context = new db_cmaEntities())
            {
                var db = context.tb_user.Where(n => n.Username == model.Username).Count();
                result = db == 0 ? false : true;
            }
            return(result);
        }
예제 #15
0
        public RoleModel Get(long id)
        {
            RoleModel result = null;

            using (var context = new db_cmaEntities())
            {
                //DOBase<tb_role> tRole = new DOBase<tb_role>(context);

                result = GetModel(context.tb_role.FirstOrDefault(n => n.Id == id), context.tb_role.FirstOrDefault(n => n.Id == id).tb_action.ToList());
            }
            return(result);
        }
예제 #16
0
        public bool RestPassword(UserInfoModel model)
        {
            using (var context = new db_cmaEntities())
            {
                var dbmodel = context.tb_user.Where(u => u.Id == model.Id).FirstOrDefault();
                if (dbmodel == null)
                {
                }

                dbmodel.Password = model.Password;
                return(context.SaveChanges() > 0);
            }
        }
예제 #17
0
        public bool Delete(int id)
        {
            var temp = false;

            using (var context = new db_cmaEntities())
            {
                DOBase <tb_message> tRole = new DOBase <tb_message>(context);
                tRole.Delete(id);

                temp = tRole.SaveChang() > 0 ? true : false;
            }
            return(temp);
        }
예제 #18
0
        public bool Add(CollectorDBModel model)
        {
            bool result = false;

            using (var context = new db_cmaEntities())
            {
                context.tb_collector.Add(new tb_collector()
                {
                    Host = model.Host, Note = model.Note
                });
                result = context.SaveChanges() > 0 ? true : false;
            }
            return(result);
        }
예제 #19
0
        public bool Edit(MessageModel model)
        {
            var temp = false;

            using (var context = new db_cmaEntities())
            {
                DOBase <tb_message> tRole = new DOBase <tb_message>(context);
                tRole.Edit(GetModel(model), new string[] { "Value", "Time" });

                temp = tRole.SaveChang() > 0 ? true : false;
                //context.Configuration.ValidateOnSaveEnabled = true;
            }
            return(temp);
        }
예제 #20
0
        public UserInfoModel Get(string username)
        {
            UserInfoModel result = null;

            using (var context = new db_cmaEntities())
            {
                var dbModel = context.tb_user.Where(n => n.Username == username).FirstOrDefault();
                if (dbModel != null)
                {
                    result = GetModel(dbModel);
                }
            }
            return(result);
        }
예제 #21
0
        public bool Add(MessageModel model)
        {
            var temp = false;

            using (var context = new db_cmaEntities())
            {
                DOBase <tb_message> tRole = new DOBase <tb_message>(context);
                tRole.Add(GetModel(model));
                context.Configuration.ValidateOnSaveEnabled = false;
                temp = tRole.SaveChang() > 0 ? true : false;
                context.Configuration.ValidateOnSaveEnabled = true;
            }
            return(temp);
        }
예제 #22
0
        public UserInfoModel Get(long id)
        {
            UserInfoModel result = null;

            using (var context = new db_cmaEntities())
            {
                var dbModel = context.tb_user.Where(n => n.Id == id).FirstOrDefault();
                if (dbModel != null)
                {
                    result = GetModel(dbModel, context.tb_user.Where(n => n.Id == id).FirstOrDefault().tb_role);
                }
            }
            return(result);
        }
예제 #23
0
        public bool Edit(MonitorItemDBModel model)
        {
            bool result = false;

            using (var context = new db_cmaEntities())
            {
                var tbItem = context.tb_monitoritem.Where(n => n.Id == model.Id).FirstOrDefault();

                tbItem.Host = model.Host;
                //tbItem.ItemType = (int)model.ItemType;
                tbItem.Name          = model.Name;
                tbItem.Note          = model.Note;
                tbItem.Paramter      = model.Paramter;
                tbItem.CollectorHost = model.CollectorHost;

                context.SaveChanges();
                result = true;
            }
            return(result);
        }
예제 #24
0
        public bool Add(MonitorItemDBModel model)
        {
            bool result = false;

            using (var context = new db_cmaEntities())
            {
                context.tb_monitoritem.Add(new tb_monitoritem()
                {
                    Host          = model.Host,
                    ItemType      = (int)model.ItemType,
                    Name          = model.Name,
                    Note          = model.Note,
                    CollectorHost = model.CollectorHost,
                    Paramter      = model.Paramter
                });

                context.SaveChanges();
                result = true;
            }
            return(result);
        }
예제 #25
0
        public bool Edit(RoleModel model)
        {
            bool result = false;

            using (var context = new db_cmaEntities())
            {
                var dbModel = context.tb_role.First(n => n.Id == model.Id);
                dbModel.Name        = model.Name;
                dbModel.cFree       = model.cFree;
                dbModel.Description = model.Description;
                if (model.ActionList.Count() > 0)
                {
                    dbModel.tb_action.Clear();
                    dbModel.tb_action = context.tb_action.Where(n => model.ActionList.Contains(n.Id)).ToList();
                }

                context.Configuration.ValidateOnSaveEnabled = false;
                context.SaveChanges();
                context.Configuration.ValidateOnSaveEnabled = true;
                result = true;
            }
            return(result);
        }
예제 #26
0
        public bool Edit(UserInfoModel model)
        {
            bool result = false;

            using (var context = new db_cmaEntities())
            {
                var dbModel = context.tb_user.First(n => n.Id == model.Id);
                dbModel.Email    = model.Email;
                dbModel.RealName = model.RealName;
                dbModel.Telphone = model.Telphone;

                if (model.RoleList.Count > 0)
                {
                    dbModel.tb_role.Clear();
                    dbModel.tb_role = context.tb_role.Where(n => model.RoleList.Contains(n.Id)).ToList();
                }

                //context.Configuration.ValidateOnSaveEnabled = false;
                context.SaveChanges();
                //context.Configuration.ValidateOnSaveEnabled = true;
                result = true;
            }
            return(result);
        }