예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #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 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);
            }
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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);
        }