Example #1
0
        public override bool Edit(ref ValidationErrors errors, SysUserConfigModel model)
        {
            try
            {
                SysUserConfig entity = m_Rep.GetById(model.Id, model.UserId);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id     = model.Id;
                entity.Name   = model.Name;
                entity.Value  = model.Value;
                entity.Type   = model.Type;
                entity.State  = model.State;
                entity.UserId = model.UserId;

                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Example #2
0
        public JsonResult SetThemes(string theme, string menu, bool topmenu)
        {
            ISysUserConfigService userConfigService = OpeCur.ServiceSession.SysUserConfig;
            string             userId = OpeCur.AccountNow.Id;
            SysUserConfigModel entity = userConfigService.GetById("themes", userId);


            if (entity != null)
            {
                entity.Value = theme;
                entity.Name  = "用户自定义主题";
                userConfigService.Modify(ref errors, entity, "Value");
            }
            else
            {
                entity = new SysUserConfigModel()
                {
                    Name   = "用户自定义主题",
                    Value  = theme,
                    Type   = "themes",
                    State  = true,
                    UserId = userId
                };
                userConfigService.Create(ref errors, entity);
            }

            Session["themes"] = theme;

            //开启顶部菜单,顶部菜单必须配置多一层
            if (topmenu)
            {
                menu = menu + ",topmenu";
            }
            SysUserConfigModel entityMenu = userConfigService.GetById("menu", userId);

            if (entityMenu != null)
            {
                entityMenu.Value = menu;
                userConfigService.Modify(ref errors, entityMenu, "Value");
            }
            else
            {
                entityMenu = new SysUserConfigModel()
                {
                    Name   = "用户自定义菜单",
                    Value  = menu,
                    Type   = "menu",
                    State  = true,
                    UserId = userId
                };
                userConfigService.Create(ref errors, entityMenu);
            }
            Session["menu"] = menu;

            OpeCur.ServiceSession.SaveChange();

            return(Json("1", JsonRequestBehavior.AllowGet));
        }
Example #3
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <SysUserConfigModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <SysUserConfigModel>(x => x.Name, "名称");
            excelFile.AddMapping <SysUserConfigModel>(x => x.Value, "值");
            excelFile.AddMapping <SysUserConfigModel>(x => x.Type, "类型");
            excelFile.AddMapping <SysUserConfigModel>(x => x.State, "状态");
            excelFile.AddMapping <SysUserConfigModel>(x => x.UserId, "所属用户");

            //SheetName
            var excelContent = excelFile.Worksheet <SysUserConfigModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new SysUserConfigModel();
                entity.Id     = row.Id;
                entity.Name   = row.Name;
                entity.Value  = row.Value;
                entity.Type   = row.Type;
                entity.State  = row.State;
                entity.UserId = row.UserId;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
Example #4
0
        public JsonResult SetThemes(string theme, string menu, bool topmenu)
        {
            SysUserConfigModel entity = userConfigBLL.GetById("themes", GetUserId());

            if (entity != null)
            {
                entity.Value = theme;
                userConfigBLL.Edit(ref errors, entity);
            }
            else
            {
                entity = new SysUserConfigModel()
                {
                    Id     = "themes",
                    Name   = "用户自定义主题",
                    Value  = theme,
                    Type   = "themes",
                    State  = true,
                    UserId = GetUserId()
                };
                userConfigBLL.Create(ref errors, entity);
            }
            Session["themes"] = theme;

            //开启顶部菜单,顶部菜单必须配置多一层
            if (topmenu)
            {
                menu = menu + ",topmenu";
            }
            SysUserConfigModel entityMenu = userConfigBLL.GetById("menu", GetUserId());

            if (entityMenu != null)
            {
                entityMenu.Value = menu;
                userConfigBLL.Edit(ref errors, entityMenu);
            }
            else
            {
                entityMenu = new SysUserConfigModel()
                {
                    Id     = "menu",
                    Name   = "用户自定义菜单",
                    Value  = menu,
                    Type   = "menu",
                    State  = true,
                    UserId = GetUserId()
                };
                userConfigBLL.Create(ref errors, entityMenu);
            }

            Session["menu"] = menu;
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
Example #5
0
        public SysUserConfigModel GetById(string type, string userId)
        {
            SysUserConfig entity = m_Rep.GetById(type, userId);

            if (entity == null)
            {
                return(null);
            }
            SysUserConfigModel model = new SysUserConfigModel();

            model.Id     = entity.Id;
            model.Name   = entity.Name;
            model.Value  = entity.Value;
            model.Type   = entity.Type;
            model.State  = entity.State;
            model.UserId = entity.UserId;
            return(model);
        }
Example #6
0
        //public override void Modify(ref ValidationErrors errors, SysUserConfigModel model, params string[] updateProperties)
        //{
        //        SysUserConfig entity = new SysUserConfig();
        //        if (entity == null)
        //        {
        //            errors.Add(Resource.Disable);
        //            return;
        //        }
        //        entity.Id = model.Id;
        //        entity.Name = model.Name;
        //        entity.Value = model.Value;
        //        entity.Type = model.Type;
        //        entity.State = model.State;
        //        entity.UserId = model.UserId;

        //        m_Rep.Modify(entity, updateProperties);
        //}


        public override void Create(ref ValidationErrors errors, SysUserConfigModel model)
        {
            SysUserConfig entity = m_Rep.GetById(model.Type, model.UserId);

            if (entity != null)
            {
                errors.Add(Resource.PrimaryRepeat);
                return;
            }
            entity        = new SysUserConfig();
            entity.Id     = ResultHelper.NewId;
            entity.Name   = model.Name;
            entity.Value  = model.Value;
            entity.Type   = model.Type;
            entity.State  = model.State;
            entity.UserId = model.UserId;

            m_Rep.Create(entity);
        }
Example #7
0
        public virtual SysUserConfigModel GetById(string id)
        {
            if (IsExists(id))
            {
                SysUserConfig      entity = m_Rep.GetById(id);
                SysUserConfigModel model  = new SysUserConfigModel();
                model.Id     = entity.Id;
                model.Name   = entity.Name;
                model.Value  = entity.Value;
                model.Type   = entity.Type;
                model.State  = entity.State;
                model.UserId = entity.UserId;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #8
0
        public virtual async Task <SysUserConfigModel> GetByIdAsync(object id)
        {
            if (IsExists(id))
            {
                SysUserConfig entity = await m_Rep.GetByIdAsync(id);

                SysUserConfigModel model = new SysUserConfigModel();
                model.Id     = entity.Id;
                model.Name   = entity.Name;
                model.Value  = entity.Value;
                model.Type   = entity.Type;
                model.State  = entity.State;
                model.UserId = entity.UserId;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #9
0
        public void GetThemes(string userid)
        {
            SysUserConfigModel entity     = userConfigBLL.GetById("themes", userid);
            SysUserConfigModel menuEntity = userConfigBLL.GetById("menu", userid);

            if (entity != null)
            {
                Session["themes"] = entity.Value;
            }
            else
            {
                Session["themes"] = "blue";
            }
            if (menuEntity != null)
            {
                Session["menu"] = menuEntity.Value;
            }
            else
            {
                Session["menu"] = "accordion";
            }
        }
Example #10
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(SysUserConfigModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                SysUserConfig entity = await m_Rep.GetByIdAsync(model.Id);

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity        = new SysUserConfig();
                entity.Id     = model.Id;
                entity.Name   = model.Name;
                entity.Value  = model.Value;
                entity.Type   = model.Type;
                entity.State  = model.State;
                entity.UserId = model.UserId;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }
Example #11
0
        public virtual bool Create(ref ValidationErrors errors, SysUserConfigModel model)
        {
            try
            {
                SysUserConfig entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity        = new SysUserConfig();
                entity.Id     = model.Id;
                entity.Name   = model.Name;
                entity.Value  = model.Value;
                entity.Type   = model.Type;
                entity.State  = model.State;
                entity.UserId = model.UserId;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }