Esempio n. 1
0
        RequestListFilterEntity SettingToFilter(FilterEntitySetting setting)
        {
            RequestListFilterEntity filter = RequestListFilterEntity.Create();

            filter.CloneKey      = new IdentKey(setting.CloneKey);
            filter.FilterName    = setting.FilterName;
            filter.StartDateTime = setting.StartDateTime;
            filter.StopDateTime  = setting.StopDateTime;

            UserEntity user = _nsiService.GetUserById(setting.ResponseId);

            filter.ResponseUser = user == null?UserEntity.Create() : user;

            user = _nsiService.GetUserById(setting.CreatorId);
            filter.CreatorUser = user == null?UserEntity.Create() : user;

            AppEntity app = _nsiService.GetAppById(setting.ApplicationId);

            filter.Application = app == null?AppEntity.Create() : app;

            OrgEntity org = _nsiService.GetOrgById(setting.OrganizationId);

            filter.Organization = org == null?OrgEntity.Create() : org;

            filter.Comments     = setting.Comments;
            filter.Subject      = setting.Subject;
            filter.Contact      = setting.Contact;
            filter.TagIdList    = setting.TagIdList;
            filter.StatusIdList = setting.StatusIdList;

            return(filter);
        }
Esempio n. 2
0
        private void Save()
        {
            if (Helpers.CheckEmpty(errorProvider1, txtFirstName, txtLastName, txtUsername,
                                   txtPassword, txtPosition))
            {
                return;
            }
            else
            {
                SaveCompleted = true;
                errorProvider1.Clear();
                UserEntity userEntity = new UserEntity();
                userEntity.LastName  = txtLastName.Text;
                userEntity.FirstName = txtFirstName.Text;
                userEntity.Username  = txtUsername.Text;
                userEntity.Password  = StringCipher.Encrypt(txtPassword.Text);
                userEntity.Position  = txtPosition.Text;
                userEntity.Phone     = txtPhone.Text;
                userEntity.Active    = chkActive.Checked;
                userEntity.BranchId  = (Guid)cboBranch.SelectedValue;

                if (userID != Guid.Empty)
                {
                    userEntity.Id = userID;
                    userEntity.Update(USER.UserName);
                    UserDao.Update(userEntity);
                }
                else
                {
                    userEntity.Id = Guid.NewGuid();
                    userEntity.Create(USER.UserName);
                    UserDao.Insert(userEntity);
                }
            }
        }
Esempio n. 3
0
        private void InitView()
        {
            _appList = _nsiService.Applications;
            _appList.Add(AppEntity.Create());

            _orgList = _nsiService.Organizations;
            _orgList.Add(OrgEntity.Create());

            _userList = _nsiService.Users;
            _userList.Add(UserEntity.Create());

            _tagList = _nsiService.Tags;

            _dialogResult = null;
            _control      = new RequestFilterControl(this);

            _caption = string.Format("Параметри пошуку звернень", "");
            _hint    = string.Format("Параметри пошуку звернень", "");

            _image = Properties.Resources.Request;

            _filterList = new List <RequestListFilterEntity>();
            foreach (RequestListFilterEntity filter in _mainController.Filters)
            {
                _filterList.Add(filter.Clone());
            }
            if (_filterOrigin == null)
            {
                Filter = RequestListFilterEntity.Create();
            }
            else
            {
                Filter = _filterOrigin.Clone();
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> SetCacheAsync(string setkey, string setvalue)
        {
            UserEntity user = new UserEntity();

            user.Create();
            return(Content("ok"));
        }
Esempio n. 5
0
        private void InsertListTest()
        {
            List <UserEntity> list = new List <UserEntity>();

            for (int i = 1; i < 5000; i++)
            {
                string key = Guid.NewGuid().ToString().Replace("-", "");

                string md5 = Md5Helper.Md5("123456");

                string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, key));

                UserEntity user = new UserEntity
                {
                    UserId    = Guid.NewGuid().ToString().Replace("-", ""),
                    Account   = "dashixiong" + i,
                    NickName  = "大师兄" + i,
                    Birthday  = DateTime.Now.AddDays(-1000),
                    Secretkey = key,
                    Password  = realPassword
                };
                user.Create();

                list.Add(user);
            }

            string time = Stopwatch(() =>
            {
                UserBll.AddUser(list);
            });

            Console.WriteLine("执行结束,耗时:" + time);
        }
Esempio n. 6
0
        public async Task SaveForm(UserEntity entity)
        {
            var db = await this.BaseRepository().BeginTrans();

            try
            {
                if (entity.Id.IsNullOrZero())
                {
                    await entity.Create();

                    await db.Insert(entity);
                }
                else
                {
                    await db.Delete <UserBelongEntity>(t => t.UserId == entity.Id);

                    // 密码不进行更新,有单独的方法更新密码
                    entity.Password = null;
                    await entity.Modify();

                    await db.Update(entity);
                }
                // 职位
                if (!string.IsNullOrEmpty(entity.PositionIds))
                {
                    foreach (long positionId in TextHelper.SplitToArray <long>(entity.PositionIds, ','))
                    {
                        UserBelongEntity positionBelongEntity = new UserBelongEntity();
                        positionBelongEntity.UserId     = entity.Id;
                        positionBelongEntity.BelongId   = positionId;
                        positionBelongEntity.BelongType = UserBelongTypeEnum.Position.ParseToInt();
                        await positionBelongEntity.Create();

                        await db.Insert(positionBelongEntity);
                    }
                }
                // 角色
                if (!string.IsNullOrEmpty(entity.RoleIds))
                {
                    foreach (long roleId in TextHelper.SplitToArray <long>(entity.RoleIds, ','))
                    {
                        UserBelongEntity departmentBelongEntity = new UserBelongEntity();
                        departmentBelongEntity.UserId     = entity.Id;
                        departmentBelongEntity.BelongId   = roleId;
                        departmentBelongEntity.BelongType = UserBelongTypeEnum.Role.ParseToInt();
                        await departmentBelongEntity.Create();

                        await db.Insert(departmentBelongEntity);
                    }
                }
                await db.CommitTrans();
            }
            catch
            {
                await db.RollbackTrans();

                throw;
            }
        }
Esempio n. 7
0
 public IActionResult AddUser(LoginModel model)
 {
     using (var db = new SlackDbContext())
     {
         db.Set <UserEntity>().Add(UserEntity.Create(model.Id, model.Pw));
     }
     return(View());
 }
 public RequestListFilterEntity() : base("ReqFilter")
 {
     FilterName    = "Новий фільтр";
     StartDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(-3);
     StopDateTime  = null;
     ResponseUser  = UserEntity.Create();
     CreatorUser   = UserEntity.Create();
     Application   = AppEntity.Create();
     Organization  = OrgEntity.Create();
 }
Esempio n. 9
0
 public MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var user = UserEntity.Create(username, password, email);
         ctx.SaveChanges();
         MembershipUser membershipUser = user.ToMembershipUser();
         status = MembershipCreateStatus.Success;
         return(membershipUser);
     }
 }
Esempio n. 10
0
 public void SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         userEntity.Modify(keyValue);
     }
     else
     {
         userEntity.Create();
     }
     service.SubmitForm(userEntity, userLogOnEntity, keyValue);
 }
Esempio n. 11
0
        RequestEntity SettingToRequest(RequestEntitySetting setting)
        {
            RequestEntity request = RequestEntity.Create();

            request.Id             = setting.Id;
            request.ReqDateTime    = setting.RequestDateTime;
            request.CreateDateTime = setting.CreateDateTime;
            request.Subject        = setting.Subject;
            request.Comments       = setting.Comments;
            request.Contact        = setting.Contact;

            AppEntity app = _nsiService.GetAppById(setting.ApplicationId);

            request.Application = app == null?AppEntity.Create() : app;

            OrgEntity org = _nsiService.GetOrgById(setting.OrganizationId);

            request.Organization = org == null?OrgEntity.Create() : org;

            UserEntity user = _nsiService.GetUserById(setting.ResponseId);

            request.ResponseUser = user == null?UserEntity.Create() : user;

            user = _nsiService.GetUserById(setting.CreatorId);
            request.CreatorUser = user == null?UserEntity.Create() : user;

            if (setting.TagIdList != null)
            {
                foreach (string id in setting.TagIdList)
                {
                    TagEntity tag = _nsiService.GetTagById(id);
                    if (tag != null)
                    {
                        request.Tags.Entities.Add(tag);
                    }
                    else
                    {
                        _logger.Warn("Can not find tag with such id = {0}", id);
                    }
                }
            }

            //request.Attaches = setting.Attaches.Clone();
            request.InfoSourceType   = setting.InfoSourceType;
            request.State            = setting.State;
            request.BugNumber        = setting.BugNumber;
            request.CMVersion        = setting.CMVersion;
            request.ComponentVersion = setting.ComponentVersion;
            request.IsImportant      = setting.IsImportant;

            return(request);
        }
Esempio n. 12
0
 public void SubmitForm(UserEntity userEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         userEntity.Modify(keyValue);
         service.Update(userEntity);
     }
     else
     {
         userEntity.Create();
         service.Insert(userEntity);
     }
 }
Esempio n. 13
0
        public int SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
        {
            var Code       = 200;
            var expression = ExtLinq.True <UserEntity>();

            expression = expression.And(t => t.F_Account.Equals(userEntity.F_Account));
            var UserEntity = service.FindEntity(expression);

            if (!string.IsNullOrEmpty(keyValue) && UserEntity != null)
            {
                UserEntity.F_Account         = userEntity.F_Account;
                UserEntity.F_DepartmentId    = userEntity.F_DepartmentId;
                UserEntity.F_Birthday        = userEntity.F_Birthday;
                UserEntity.F_Email           = userEntity.F_Email;
                UserEntity.F_RoleId          = userEntity.F_RoleId;
                UserEntity.F_WeChat          = userEntity.F_WeChat;
                UserEntity.F_DutyId          = userEntity.F_DutyId;
                UserEntity.F_RealName        = userEntity.F_RealName;
                UserEntity.F_Gender          = userEntity.F_Gender;
                UserEntity.F_ManagerId       = userEntity.F_ManagerId;
                UserEntity.F_MobilePhone     = userEntity.F_MobilePhone;
                UserEntity.F_IsAdministrator = userEntity.F_IsAdministrator;
                UserEntity.F_Description     = userEntity.F_Description;
                UserEntity.F_EnabledMark     = userEntity.F_EnabledMark;
                var leave  = leaveApp.GetFormByUserID(UserEntity.F_Id);
                var depart = new OrganizeApp().GetForm(UserEntity.F_DepartmentId);
                foreach (var item in leave)
                {
                    item.F_Department = depart.F_FullName;
                    leaveApp.SubmitForm(item, item.F_Id);
                }
                service.SubmitForm(UserEntity, userLogOnEntity, keyValue);
            }
            else
            {
                if (UserEntity != null)
                {
                    return(Code = 100);
                }
                else
                {
                    userEntity.Create();
                }

                service.SubmitForm(userEntity, userLogOnEntity, keyValue);
            }


            return(Code);
        }
Esempio n. 14
0
        public RequestEntity() : base("Request")
        {
            Tags           = new EntityList <TagEntity>();
            Attaches       = new EntityList <AttachEntity>();
            InfoSourceType = InfoSourceType.Call;
            State          = RequestState.Open;
            Organization   = OrgEntity.Create();
            Application    = AppEntity.Create();
            ResponseUser   = UserEntity.Create();
            CreatorUser    = UserEntity.Create();
            CreateDateTime = DateHlp.GetDateTime_hhmmss();
            ReqDateTime    = DateHlp.GetDateTime_hhmmss();

            PropertyChanged += new PropertyChangedEventHandler(RequestEntity_PropertyChanged);
        }
Esempio n. 15
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (MustAcceptsPrivacyPolicy && !Input.AcceptPrivacyPolicy)
            {
                var field = nameof(Input.AcceptPrivacyPolicy);

                ModelState.AddModelError($"{nameof(Input)}.{field}", T[$"{field}Error"]);
            }

            if (MustAcceptsTermsOfService && !Input.AcceptTermsOfService)
            {
                var field = nameof(Input.AcceptTermsOfService);

                ModelState.AddModelError($"{nameof(Input)}.{field}", T[$"{field}Error"]);
            }

            var emailCheck = await emailValidator.ValidateAsync(Input.Email);

            if (emailCheck.Errors.Any())
            {
                ModelState.AddModelErrors(emailCheck);
            }

            if (ModelState.IsValid)
            {
                var user = UserEntity.Create(Input.Email);

                var result = await UserManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    var callbackCode = await UserManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id.ToString(), callbackCode, Request.Scheme);

                    await emailSender.SendEmailConfirmationAsync(Input.Email, callbackUrl);

                    await SignInManager.SignInAsync(user, false);

                    return(RedirectTo(ReturnUrl));
                }

                ModelState.AddModelErrors(result);
            }

            return(Page());
        }
        public async Task <IActionResult> OnPostConfirmationAsync()
        {
            if (MustAcceptsPrivacyPolicy && !Input.AcceptPrivacyPolicy)
            {
                var field = nameof(Input.AcceptPrivacyPolicy);

                ModelState.AddModelError($"{nameof(Input)}.{field}", T[$"{field}Error"]);
            }

            if (MustAcceptsTermsOfService && !Input.AcceptTermsOfService)
            {
                var field = nameof(Input.AcceptTermsOfService);

                ModelState.AddModelError($"{nameof(Input)}.{field}", T[$"{field}Error"]);
            }

            if (ModelState.IsValid)
            {
                var loginInfo = await SignInManager.GetExternalLoginInfoAsync();

                if (loginInfo == null)
                {
                    throw new ApplicationException("Error loading external login information during confirmation.");
                }

                var user = UserEntity.Create(Input.Email);

                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user, loginInfo);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, false);

                        return(RedirectTo(ReturnUrl));
                    }
                }

                ModelState.AddModelErrors(result);
            }

            return(Page());
        }
Esempio n. 17
0
        public MainController()
        {
            IServiceMgr serviceMgr = ServiceMgr.Current;

            _logMgr           = serviceMgr.GetInstance <ILogMgr>();
            _connection       = serviceMgr.GetInstance <IDbConnection>();
            _messageBoxMgr    = serviceMgr.GetInstance <IMessageBoxMgr>();
            _viewFormMgr      = serviceMgr.GetInstance <IViewFormMgr>();
            _commonDbAccessor = serviceMgr.GetInstance <ICommonDbAccessor>();
            _nsiController    = serviceMgr.GetInstance <INsiController>();
            _eventMgr         = serviceMgr.GetInstance <IEventMgr>();
            _logger           = _logMgr.GetLogger("MainController");
            _logger.Debug("Create.");

            _isFirstConnect = true;
            _currentUser    = UserEntity.Create();
        }
        public void TestMethod_Insert_T()
        {
            UserEntity user = new UserEntity
            {
                Name        = "小师弟",
                Age         = 18,
                Sex         = 1,
                Description = "测试实体插入",
                Mobile      = "15890909090"
            };

            user.Create();

            BaseBLL <UserEntity> bll = new BaseBLL <UserEntity>();
            int res = bll.Add(user);

            Console.WriteLine("执行结果:{0}", res);
        }
Esempio n. 19
0
        private void InsertTest(int toatl = 10)
        {
            Console.WriteLine("\r\n开始测试插入数据...\r\n");

            string time = Stopwatch(() =>
            {
                for (int i = 1; i < toatl; i++)
                {
                    string time2 = Stopwatch(() =>
                    {
                        string key = Guid.NewGuid().ToString().Replace("-", "");

                        string md5 = Md5Helper.Md5("123456");

                        string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, key));

                        UserEntity user = new UserEntity
                        {
                            Account   = "System" + i,
                            NickName  = "大师兄" + i,
                            Birthday  = DateTime.Now.AddDays(-1000),
                            Secretkey = key,
                            Password  = realPassword,
                            Gender    = 1,
                            SortCode  = i
                                        //RoleId = CommonHelper.GetGuid()
                        };
                        user.Create();

                        ////表名
                        //string table = EntityAttributeHelper.GetEntityTable<UserEntity>();
                        ////获取不做映射的字段
                        //List<string> notMappedField = EntityAttributeHelper.GetNotMappedFields<UserEntity>();

                        bool res = _userBll.AddUser(user);
                    });

                    Console.WriteLine("开始测试" + i + ",耗时:" + time2);
                }
            });

            Console.WriteLine("执行结束,耗时:" + time);
        }
Esempio n. 20
0
        public void SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                userEntity.Modify(keyValue);
            }
            else
            {
                userEntity.Create();
            }
            service.SubmitForm(userEntity, userLogOnEntity, keyValue);

            try
            {
                //添加日志
                LogMess.addLog(DbLogType.Update.ToString(), "修改成功", "修改用户信息【" + userEntity.F_RealName + "】成功!");
            }
            catch { }
        }
Esempio n. 21
0
        private void InitView()
        {
            _image   = Properties.Resources.Request;
            _appList = _nsiService.Applications;
            _appList.Add(AppEntity.Create());

            _orgList = _nsiService.Organizations;
            _orgList.Add(OrgEntity.Create());

            _userList = _nsiService.Users;
            _userList.Add(UserEntity.Create());

            _tagList = _nsiService.Tags;
            _tagList.Add(TagEntity.Create());

            _dialogResult = null;
            _control      = new RequestEditControl(this);

            SetCaption();

            _eventMgr.GetEvent <RequestChangedEvent>().Subscribe(OnRequestChanged);
        }
        public void TestMethod_BatchInsert_T()
        {
            List <UserEntity> userEntities = new List <UserEntity>();

            for (int i = 0; i < 100; i++)
            {
                UserEntity user = new UserEntity
                {
                    Name        = "小师弟",
                    Age         = 18,
                    Sex         = 1,
                    Description = "测试实体插入",
                    Mobile      = "15890909090"
                };
                user.Create();
                userEntities.Add(user);
            }

            BaseBLL <UserEntity> bll = new BaseBLL <UserEntity>();
            int res = bll.AddList(userEntities);

            Console.WriteLine("执行结果:{0}", res);
        }
Esempio n. 23
0
 public bool SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue, string roleId)
 {
     if (string.IsNullOrEmpty(keyValue))
     {
         UserEntity userE = service.FindEntity(t => t.F_Account == userEntity.F_Account);
         if (userE != null)
         {
             throw new Exception("用户已存在");
         }
     }
     userEntity.F_RoleId      = roleId;
     userEntity.F_EnabledMark = true;
     if (!string.IsNullOrEmpty(keyValue))
     {
         userEntity.Modify(keyValue);
     }
     else
     {
         userEntity.Create();
     }
     service.SubmitForm(userEntity, userLogOnEntity, keyValue);
     return(true);
 }
Esempio n. 24
0
        /// <summary>
        /// 保存机构表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="organizeEntity">机构实体</param>
        /// <returns></returns>
        public void SaveForm(string keyValue, OrganizeEntity organizeEntity)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                organizeEntity.Modify(keyValue);
                this.BaseRepository().Update(organizeEntity);
            }
            else
            {
                organizeEntity.Create();

                organizeEntity.EnCode = Str.PinYin(organizeEntity.FullName);//登录名为机构名拼音首字母
                this.BaseRepository().Insert(organizeEntity);

                IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
                try
                {
                    //新增默认管理部门
                    DepartmentEntity department = new DepartmentEntity();
                    department.OrganizeId = organizeEntity.OrganizeId;
                    department.ParentId   = "0";
                    department.EnCode     = organizeEntity.EnCode + "01";
                    department.FullName   = organizeEntity.FullName + "管理部";
                    department.Create();
                    db.Insert(department);

                    //新增默认靓号角色
                    RoleEntity role = new RoleEntity();
                    role.OrganizeId = organizeEntity.OrganizeId;
                    role.Category   = 1;//分类1 - 角色2 - 岗位3 - 职位4 - 工作组
                    role.EnCode     = organizeEntity.EnCode + "01";
                    role.FullName   = organizeEntity.FullName + "管理";
                    role.Create();
                    db.Insert(role);


                    #region 授权功能
                    var AuthorizeList = db.FindList <AuthorizeEntity>(t => t.ObjectId == "48c566d6-3dfb-4b08-8f62-a662642db300");
                    foreach (AuthorizeEntity item in AuthorizeList)
                    {
                        AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                        authorizeEntity.Create();
                        authorizeEntity.Category = 2;  //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组
                        authorizeEntity.ObjectId = role.RoleId;
                        authorizeEntity.ItemType = item.ItemType;
                        authorizeEntity.ItemId   = item.ItemId;
                        authorizeEntity.SortCode = item.SortCode;
                        db.Insert(authorizeEntity);
                    }
                    #endregion

                    #region 数据权限
                    var authorizeDataList = db.FindList <AuthorizeDataEntity>(t => t.ObjectId == "48c566d6-3dfb-4b08-8f62-a662642db300");
                    foreach (AuthorizeDataEntity item in authorizeDataList)
                    {
                        AuthorizeDataEntity authorizeDataEntity = new AuthorizeDataEntity();
                        authorizeDataEntity.Create();
                        authorizeDataEntity.AuthorizeType = item.AuthorizeType; //授权类型: 1 - 仅限本人2 - 仅限本人及下属3 - 所在部门4 - 所在公司5 - 按明细设置
                        authorizeDataEntity.Category      = 2;                  //对象分类: 1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组
                        authorizeDataEntity.ObjectId      = role.RoleId;
                        authorizeDataEntity.IsRead        = item.IsRead;
                        authorizeDataEntity.SortCode      = item.SortCode;
                        db.Insert(authorizeDataEntity);
                    }
                    #endregion



                    //新增默认用户
                    UserEntity userEntity = new UserEntity();
                    userEntity.Create();
                    userEntity.Account      = organizeEntity.EnCode;//登录名为机构名拼音首字母
                    userEntity.RealName     = organizeEntity.FullName;
                    userEntity.OrganizeId   = organizeEntity.OrganizeId;
                    userEntity.DepartmentId = department.DepartmentId;
                    userEntity.RoleId       = role.RoleId;
                    userEntity.Secretkey    = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower();
                    userEntity.Password     = Md5Helper.MD5(DESEncrypt.Encrypt(Md5Helper.MD5("0000", 32).ToLower(), userEntity.Secretkey).ToLower(), 32).ToLower();
                    db.Insert(userEntity);

                    //新增默认用户关系
                    UserRelationEntity userRelationEntity = new UserRelationEntity();
                    userRelationEntity.Create();
                    userRelationEntity.Category = 2;//登录名为机构名拼音首字母
                    userRelationEntity.UserId   = userEntity.UserId;
                    userRelationEntity.ObjectId = userEntity.RoleId;
                    db.Insert(userRelationEntity);

                    db.Commit();
                }
                catch (Exception)
                {
                    db.Rollback();
                    throw;
                }
            }
        }
Esempio n. 25
0
        /// <summary>
        /// 保存用户表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="userEntity">用户实体</param>
        /// <returns></returns>
        public string SaveForm(string keyValue, UserEntity userEntity)
        {
            try
            {
                using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction())
                {
                    #region 基本信息
                    if (!string.IsNullOrEmpty(keyValue))
                    {
                        userEntity.Modify(keyValue);
                        userEntity.Password = null;
                        Base_User model = Base_User.SingleOrDefault("where UserId=@0", keyValue);
                        model        = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, model);
                        model.UserId = keyValue;
                        model.Update();
                    }
                    else
                    {
                        userEntity.Create();
                        keyValue               = userEntity.UserId;
                        userEntity.Secretkey   = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower();
                        userEntity.Password    = Md5Helper.MD5(DESEncrypt.Encrypt(userEntity.Password, userEntity.Secretkey).ToLower(), 32).ToLower();
                        userEntity.EnabledMark = 1;
                        userEntity.DeleteMark  = 0;
                        Base_User model = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, null);
                        model.Insert();
                    }
                    #endregion

                    #region 默认添加 角色、岗位、职位
                    Base_UserRelation.Delete("where UserId=@0 and IsDefault=1", userEntity.UserId);
                    List <UserRelationEntity> userRelationEntitys = new List <UserRelationEntity>();
                    //角色 这里多个角色逻辑处理
                    //if (!string.IsNullOrEmpty(userEntity.RoleId))
                    //{
                    //    userRelationEntitys.Add(new UserRelationEntity
                    //    {
                    //        Category = (int)QSDMS.Model.Enums.UserCategoryEnum.角色,
                    //        UserRelationId = Guid.NewGuid().ToString(),
                    //        UserId = userEntity.UserId,
                    //        ObjectId = userEntity.RoleId,
                    //        CreateDate = DateTime.Now,
                    //        CreateUserId = OperatorProvider.Provider.Current().UserId,
                    //        CreateUserName = OperatorProvider.Provider.Current().UserName,
                    //        IsDefault = 1,
                    //    });
                    //}
                    //一个用户多个角色
                    if (!string.IsNullOrEmpty(userEntity.RoleId))
                    {
                        Base_UserRole.Delete("where UserId=@0", userEntity.UserId);
                        string[] roles = userEntity.RoleId.Split(',');
                        for (int i = 0; i < roles.Length; i++)
                        {
                            //用户角色表
                            string roleid   = roles[i];
                            var    userrole = new UserRoleEntity();
                            userrole.UserRoleId = Util.Util.NewUpperGuid();
                            userrole.UserId     = userEntity.UserId;
                            userrole.RoleId     = roleid.Split('|')[0];
                            userrole.RoleName   = roleid.Split('|')[1];
                            Base_UserRole model = EntityConvertTools.CopyToModel <UserRoleEntity, Base_UserRole>(userrole, null);
                            model.Insert();

                            //用户关系表
                            userRelationEntitys.Add(new UserRelationEntity
                            {
                                Category       = (int)QSDMS.Model.Enums.UserCategoryEnum.角色,
                                UserRelationId = Guid.NewGuid().ToString(),
                                UserId         = userEntity.UserId,
                                ObjectId       = userrole.RoleId,
                                CreateDate     = DateTime.Now,
                                CreateUserId   = OperatorProvider.Provider.Current().UserId,
                                CreateUserName = OperatorProvider.Provider.Current().UserName,
                                IsDefault      = 1,
                            });
                        }
                    }
                    //岗位
                    if (!string.IsNullOrEmpty(userEntity.DutyId))
                    {
                        userRelationEntitys.Add(new UserRelationEntity
                        {
                            Category       = (int)QSDMS.Model.Enums.UserCategoryEnum.岗位,
                            UserRelationId = Guid.NewGuid().ToString(),
                            UserId         = userEntity.UserId,
                            ObjectId       = userEntity.DutyId,
                            CreateDate     = DateTime.Now,
                            CreateUserId   = OperatorProvider.Provider.Current().UserId,
                            CreateUserName = OperatorProvider.Provider.Current().UserName,
                            IsDefault      = 1,
                        });
                    }
                    //职位
                    if (!string.IsNullOrEmpty(userEntity.PostId))
                    {
                        userRelationEntitys.Add(new UserRelationEntity
                        {
                            Category       = (int)QSDMS.Model.Enums.UserCategoryEnum.职位,
                            UserRelationId = Guid.NewGuid().ToString(),
                            UserId         = userEntity.UserId,
                            ObjectId       = userEntity.PostId,
                            CreateDate     = DateTime.Now,
                            CreateUserId   = OperatorProvider.Provider.Current().UserId,
                            CreateUserName = OperatorProvider.Provider.Current().UserName,
                            IsDefault      = 1,
                        });
                    }
                    //插入用户关系表
                    foreach (UserRelationEntity userRelationItem in userRelationEntitys)
                    {
                        Base_UserRelation model = EntityConvertTools.CopyToModel <UserRelationEntity, Base_UserRelation>(userRelationItem, null);
                        model.Insert();
                    }
                    #endregion

                    Base_UserAuthorize.Delete("where UserId=@0", userEntity.UserId);
                    //插入用户对应数据权限
                    if (!string.IsNullOrEmpty(userEntity.AuthorizeDataId))
                    {
                        string[] uthorizeDatas = userEntity.AuthorizeDataId.Split(',');
                        for (int i = 0; i < uthorizeDatas.Length; i++)
                        {
                            string objectid      = uthorizeDatas[i];
                            var    userAuthorize = new UserAuthorizeEntity();
                            userAuthorize.UserAuthorizeId = Util.Util.NewUpperGuid();
                            userAuthorize.UserId          = userEntity.UserId;
                            userAuthorize.ObjectId        = objectid.Split('|')[0];
                            userAuthorize.ObjectName      = objectid.Split('|')[1];
                            Base_UserAuthorize model = EntityConvertTools.CopyToModel <UserAuthorizeEntity, Base_UserAuthorize>(userAuthorize, null);
                            model.Insert();
                        }
                    }

                    tran.Complete();
                }
                return(keyValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 26
0
        /// <summary>
        /// 新增一个用户
        /// </summary>
        /// <param name="userEntity">用户实体</param>
        /// <returns></returns>
        public bool AddUser(UserEntity userEntity)
        {
            userEntity.Create();
            int res = this.BaseRepository().Insert(userEntity);

            if (res > 0)
            {
                #region 添加角色、岗位、职位信息

                //删除历史用户角色关系
                res = this.BaseRepository().Delete <UserRelationEntity>(u => u.Id == userEntity.Id && u.IsDefault == true);
                //用户关系
                List <UserRelationEntity> userRelation = new List <UserRelationEntity>();
                //角色
                if (!string.IsNullOrEmpty(userEntity.RoleId))
                {
                    userRelation.Add(new UserRelationEntity
                    {
                        Category       = 2,
                        Id             = CommonHelper.GetGuid(),
                        UserId         = userEntity.Id,
                        ObjectId       = userEntity.RoleId,
                        CreateDate     = DateTime.Now,
                        CreateUserId   = OperatorProvider.Provider.Current().UserId,
                        CreateUserName = OperatorProvider.Provider.Current().UserName,
                        IsDefault      = true
                    });
                }
                //岗位
                if (!string.IsNullOrEmpty(userEntity.DutyId))
                {
                    userRelation.Add(new UserRelationEntity
                    {
                        Category       = 3,
                        Id             = CommonHelper.GetGuid(),
                        UserId         = userEntity.Id,
                        ObjectId       = userEntity.DutyId,
                        CreateDate     = DateTime.Now,
                        CreateUserId   = OperatorProvider.Provider.Current().UserId,
                        CreateUserName = OperatorProvider.Provider.Current().UserName,
                        IsDefault      = true
                    });
                }
                //职位
                if (!string.IsNullOrEmpty(userEntity.PostId))
                {
                    userRelation.Add(new UserRelationEntity
                    {
                        Category       = 3,
                        Id             = CommonHelper.GetGuid(),
                        UserId         = userEntity.Id,
                        ObjectId       = userEntity.PostId,
                        CreateDate     = DateTime.Now,
                        CreateUserId   = OperatorProvider.Provider.Current().UserId,
                        CreateUserName = OperatorProvider.Provider.Current().UserName,
                        IsDefault      = true
                    });
                }
                //保持用户角色关系
                res = this.BaseRepository().Insert <UserRelationEntity>(userRelation);

                #endregion 添加角色、岗位、职位信息
            }

            return(res > 0);
        }
Esempio n. 27
0
        /// <summary>
        /// 保存用户表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="userEntity">用户实体</param>
        /// <param name="objectId">用户ID</param>
        /// <returns></returns>
        public bool AddUser(string keyValue, UserEntity userEntity, out string objectId)
        {
            bool isSucc = false;

            if (!string.IsNullOrEmpty(keyValue))
            {
                //更新操作
                userEntity.Modify(keyValue);
                int res = this.BaseRepository().Update <UserEntity>(userEntity);
                isSucc = res > 0;
            }
            else
            {
                //新增操作
                userEntity.Create();

                int res = this.BaseRepository().Insert <UserEntity>(userEntity);
                isSucc = res > 0;
            }

            #region 添加角色、岗位、职位信息

            //删除历史用户角色关系
            this.BaseRepository().Delete <UserRelationEntity>(u => u.IsDefault == true && u.Id == userEntity.Id);
            //用户关系
            List <UserRelationEntity> userRelation = new List <UserRelationEntity>();
            //角色
            if (!string.IsNullOrEmpty(userEntity.RoleId))
            {
                userRelation.Add(new UserRelationEntity
                {
                    Category       = 2,
                    Id             = CommonHelper.GetGuid(),
                    UserId         = userEntity.Id,
                    ObjectId       = userEntity.RoleId,
                    CreateDate     = DateTime.Now,
                    CreateUserId   = OperatorProvider.Provider.Current().UserId,
                    CreateUserName = OperatorProvider.Provider.Current().UserName,
                    IsDefault      = true
                });
            }
            //岗位
            if (!string.IsNullOrEmpty(userEntity.DutyId))
            {
                userRelation.Add(new UserRelationEntity
                {
                    Category       = 3,
                    Id             = CommonHelper.GetGuid(),
                    UserId         = userEntity.Id,
                    ObjectId       = userEntity.DutyId,
                    CreateDate     = DateTime.Now,
                    CreateUserId   = OperatorProvider.Provider.Current().UserId,
                    CreateUserName = OperatorProvider.Provider.Current().UserName,
                    IsDefault      = true
                });
            }
            //职位
            if (!string.IsNullOrEmpty(userEntity.PostId))
            {
                userRelation.Add(new UserRelationEntity
                {
                    Category       = 3,
                    Id             = CommonHelper.GetGuid(),
                    UserId         = userEntity.Id,
                    ObjectId       = userEntity.PostId,
                    CreateDate     = DateTime.Now,
                    CreateUserId   = OperatorProvider.Provider.Current().UserId,
                    CreateUserName = OperatorProvider.Provider.Current().UserName,
                    IsDefault      = true
                });
            }
            //保持用户角色关系
            this.BaseRepository().Insert <UserRelationEntity>(userRelation);

            #endregion 添加角色、岗位、职位信息

            objectId = userEntity.Id;
            return(isSucc);
        }
Esempio n. 28
0
        /// <summary>
        /// 新增下级代理
        /// </summary>
        /// <param name="organizeEntity"></param>
        public void SaveNewAgent(OrganizeEntity organizeEntity)
        {
            IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();

            try
            {
                #region 新增机构
                //父机构
                if (organizeEntity.ParentId == null)
                {
                    throw new Exception("上级机构不能为空!");
                }

                if (organizeEntity.ParentId != "0")
                {
                    var parentEntity = this.BaseRepository().FindEntity(organizeEntity.ParentId);
                    organizeEntity.Category = parentEntity.Category + 1;

                    //顶级机构
                    IEnumerable <OrganizeEntity> topList = GetParentIdByOrgId(organizeEntity.ParentId);
                    if (topList.Count() > 0 && string.IsNullOrEmpty(organizeEntity.Img1))
                    {
                        OrganizeEntity topEntity = topList.First();
                        organizeEntity.TopOrganizeId = topEntity.OrganizeId;//顶级机构
                    }
                }
                else
                {
                    organizeEntity.Category = 0;
                }
                //如果图片为空
                if (string.IsNullOrEmpty(organizeEntity.Img1))
                {
                    organizeEntity.Img1 = Config.GetValue("Img1");
                    organizeEntity.Img2 = Config.GetValue("Img2");
                    organizeEntity.Img3 = Config.GetValue("Img3");
                    organizeEntity.Img4 = Config.GetValue("Img4");
                }

                organizeEntity.Create();

                db.Insert(organizeEntity);
                #endregion

                #region 新增默认管理部门
                DepartmentEntity department = new DepartmentEntity();
                department.OrganizeId = organizeEntity.OrganizeId;
                department.ParentId   = "0";
                department.EnCode     = organizeEntity.OuterPhone;//账号
                department.FullName   = organizeEntity.FullName;
                department.Create();
                db.Insert(department);
                #endregion

                #region 新增默认靓号角色
                RoleEntity role = new RoleEntity();
                role.OrganizeId = organizeEntity.OrganizeId;
                role.Category   = 1;                         //分类1 - 角色2 - 岗位3 - 职位4 - 工作组
                role.EnCode     = organizeEntity.OuterPhone; //账号
                role.FullName   = organizeEntity.FullName;
                role.Create();
                db.Insert(role);
                #endregion

                #region 授权功能
                //string copyObject = "f7e8ce33-ce79-460f-a24c-d0ed53001477";//复制二级唐山和讯老李17040258888管理
                ////临沂大华单独处理
                //if (organizeEntity.TopOrganizeId== "a5a962da-57e1-4ad4-87b2-bbdcd1b7cc92" && organizeEntity.Category != 0)
                //{
                //    copyObject = "1062959a-bd81-4547-ac9a-c51f750ea237";//珊哥在线管理(只显示机构,其它什么都没有)
                //}
                //else
                //{
                //    if (organizeEntity.Category < 1)
                //    {
                //        copyObject = "209b63c7-3638-45e7-b24a-cf88f6d5c9dd";//复制唐山和讯老李17040258888管理(零,一级)
                //    }
                //}
                string copyObject = "c1139630-d98f-4412-be8e-2c13cfd11380";//默认三级:不显示靓号库,看不到底价
                //临沂大华单独处理
                if (organizeEntity.TopOrganizeId == "a5a962da-57e1-4ad4-87b2-bbdcd1b7cc92" && organizeEntity.Category != 0)
                {
                    copyObject = "fbf669b2-e7fc-450d-a3e5-20e005cab567";//测试4级机构    18777777777(只显示机构,其它什么都没有)
                }
                else
                {
                    if (organizeEntity.Category <= 1)
                    {
                        copyObject = "094115aa-4635-4ad0-b798-76d34c6d4e72";//零级:含基础设置 18660999999
                    }
                    else if (organizeEntity.Category == 2)
                    {
                        copyObject = "12de4dd4-156b-4495-8f43-e235d6de85d2";//二级:可看低价,无基础设置18666666666
                    }
                }


                var AuthorizeList = db.FindList <AuthorizeEntity>(t => t.ObjectId == copyObject);
                foreach (AuthorizeEntity item in AuthorizeList)
                {
                    AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                    authorizeEntity.Create();
                    authorizeEntity.Category = 2;             //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组
                    authorizeEntity.ObjectId = role.RoleId;   //角色id,角色限定了机构和部门
                    authorizeEntity.ItemType = item.ItemType; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单
                    authorizeEntity.ItemId   = item.ItemId;   //项目主键
                    authorizeEntity.SortCode = item.SortCode;
                    db.Insert(authorizeEntity);
                }
                #endregion

                #region 数据权限 就一个
                AuthorizeDataEntity authorizeDataEntity = new AuthorizeDataEntity();
                authorizeDataEntity.Create();
                authorizeDataEntity.AuthorizeType = 4;           //授权类型: 1 - 仅限本人2 - 仅限本人及下属3 - 所在部门4 - 所在公司5 - 按明细设置
                authorizeDataEntity.Category      = 2;           //对象分类: 1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组
                authorizeDataEntity.ObjectId      = role.RoleId; //角色id,角色限定了机构和部门
                authorizeDataEntity.IsRead        = 0;
                authorizeDataEntity.SortCode      = 1;
                db.Insert(authorizeDataEntity);
                #endregion

                #region 新增默认用户
                UserEntity userEntity = new UserEntity();
                userEntity.Create();
                userEntity.Account      = organizeEntity.OuterPhone; //登录名为机构名拼音首字母organizeEntity.EnCode
                userEntity.RealName     = organizeEntity.Manager;    //organizeEntity.FullName
                userEntity.WeChat       = organizeEntity.ShortName;  //微信昵称
                userEntity.OrganizeId   = organizeEntity.OrganizeId;
                userEntity.DepartmentId = department.DepartmentId;
                userEntity.RoleId       = role.RoleId;
                userEntity.Gender       = 1;
                userEntity.Secretkey    = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower();
                userEntity.Password     = Md5Helper.MD5(DESEncrypt.Encrypt(Md5Helper.MD5("0000", 32).ToLower(), userEntity.Secretkey).ToLower(), 32).ToLower();
                db.Insert(userEntity);
                #endregion

                #region 新增默认用户关系
                UserRelationEntity userRelationEntity = new UserRelationEntity();
                userRelationEntity.Create();
                userRelationEntity.Category = 2;//登录名为机构名拼音首字母
                userRelationEntity.UserId   = userEntity.UserId;
                userRelationEntity.ObjectId = userEntity.RoleId;
                db.Insert(userRelationEntity);
                #endregion

                db.Commit();
            }
            catch (Exception)
            {
                db.Rollback();
                throw;
            }
        }
Esempio n. 29
0
        protected override void Seed(JuCheapContext context)
        {
            if (context.Set <UserEntity>().Any())
            {
                return;
            }

            #region 用户

            var admin = new UserEntity
            {
                User           = "******",
                xingming       = "超级管理员",
                Pwd            = "qwaszx",
                Email          = "*****@*****.**",
                Status         = 2,
                CreateDateTime = now
            };
            admin.Create();
            var guest = new UserEntity
            {
                User           = "******",
                xingming       = "游客",
                Pwd            = "qwaszx",
                Email          = "*****@*****.**",
                Status         = 2,
                CreateDateTime = now
            };
            guest.Create();
            //用户
            var user = new List <UserEntity>
            {
                admin,
                guest
            };
            #endregion

            #region 菜单

            var system = new MenuEntity
            {
                Name           = "系统设置",
                Url            = "#",
                Type           = 1,
                CreateDateTime = now,
                Order          = 1
            };
            system.Create();
            var menuMgr = new MenuEntity
            {
                ParentId       = system.Id,
                Name           = "菜单管理",
                Url            = "/Adm/Menu/Index",
                Type           = 2,
                CreateDateTime = now,
                Order          = 2
            };//2
            menuMgr.Create();
            var roleMgr = new MenuEntity
            {
                ParentId       = system.Id,
                Name           = "角色管理",
                Url            = "/Adm/Role/Index",
                Type           = 2,
                CreateDateTime = now,
                Order          = 3
            };//3
            roleMgr.Create();
            var userMgr = new MenuEntity
            {
                ParentId       = system.Id,
                Name           = "用户管理",
                Url            = "/Adm/User/Index",
                Type           = 2,
                CreateDateTime = now,
                Order          = 4
            };//4
            userMgr.Create();
            var roleAuthMgr = new MenuEntity
            {
                ParentId       = system.Id,
                Name           = "角色授权",
                Url            = "/Adm/Role/AuthMenus",
                Type           = 2,
                CreateDateTime = now,
                Order          = 5
            };//5
            roleAuthMgr.Create();
            var mail = new MenuEntity
            {
                Name           = "邮件系统",
                Url            = "#",
                Type           = 1,
                CreateDateTime = now,
                Order          = 6
            };//6
            mail.Create();
            var mailMgr = new MenuEntity
            {
                ParentId       = mail.Id,
                Name           = "邮件列表",
                Url            = "/Adm/Email/Index",
                Type           = 2,
                CreateDateTime = now,
                Order          = 7
            };//7
            mailMgr.Create();
            var log = new MenuEntity
            {
                Name           = "日志查看",
                Url            = "#",
                Type           = 1,
                CreateDateTime = now,
                Order          = 8
            };//8
            log.Create();
            var logLogin = new MenuEntity
            {
                ParentId       = log.Id,
                Name           = "登录日志",
                Url            = "/Adm/Loginlog/Index",
                Type           = 2,
                CreateDateTime = now,
                Order          = 9
            };
            logLogin.Create();
            var logView = new MenuEntity
            {
                ParentId       = log.Id,
                Name           = "访问日志",
                Url            = "/Adm/PageView/Index",
                Type           = 2,
                CreateDateTime = now,
                Order          = 10
            };
            logView.Create();
            //菜单
            var menus = new List <MenuEntity>
            {
                system,
                menuMgr,
                roleMgr,
                userMgr,
                roleAuthMgr,
                mail,
                mailMgr,
                log,
                logLogin,
                logView
            };
            var menuBtns = GetMenuButtons(menuMgr.Id, "Menu"); //13
            var rolwBtns = GetMenuButtons(roleMgr.Id, "Role"); //16
            var userBtns = GetMenuButtons(userMgr.Id, "User"); //19
            var userAuth = new MenuEntity
            {
                ParentId       = userMgr.Id,
                Name           = "用户角色授权",
                Url            = string.Format("/Adm/{0}/Authen", "User"),
                Type           = 3,
                CreateDateTime = now,
                Order          = 11
            };
            userAuth.Create();
            userBtns.Add(userAuth);   //20

            menus.AddRange(menuBtns); //23
            menus.AddRange(rolwBtns); //26
            menus.AddRange(userBtns); //29
            var demo = new MenuEntity
            {
                ParentId       = string.Empty,
                Name           = "示例文档",
                Url            = "#",
                Type           = 1,
                Order          = 12,
                CreateDateTime = now
            };//30
            demo.Create();
            var demoAdv = new MenuEntity
            {
                ParentId       = string.Empty, Name = "高级示例", Url = "#", Type = 1,
                Order          = 13,
                CreateDateTime = now
            };//31
            demoAdv.Create();
            var mailSend = new MenuEntity {
                ParentId = mailMgr.Id, Name = "发送邮件", Url = "/Adm/Email/Add", Type = 3, Order = 14, CreateDateTime = now
            };
            mailSend.Create();
            menus.Add(mailSend);
            menus.Add(demo);
            menus.Add(demoAdv);

            var demoMenus = new List <MenuEntity>
            {
                new MenuEntity {
                    ParentId = demo.Id, Name = "按钮", Url = "/Adm/Demo/Base", Type = 2, Order = 15, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demo.Id, Name = "ICON图标", Url = "/Adm/Demo/Fontawosome", Type = 2, Order = 16, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demo.Id, Name = "表单", Url = "/Adm/Demo/Form", Type = 2, Order = 17, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demo.Id, Name = "高级控件", Url = "/Adm/Demo/Advance", Type = 2, Order = 18, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demo.Id, Name = "相册", Url = "/Adm/Demo/Gallery", Type = 2, Order = 19, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demo.Id, Name = "个人主页", Url = "/Adm/Demo/Profile", Type = 2, Order = 20, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demo.Id, Name = "邮件-收件箱", Url = "/Adm/Demo/InBox", Type = 2, Order = 21, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demo.Id, Name = "邮件-查看邮件", Url = "/Adm/Demo/InBoxDetail", Type = 2, Order = 22, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demo.Id, Name = "邮件-写邮件", Url = "/Adm/Demo/InBoxCompose", Type = 2, Order = 23, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demoAdv.Id, Name = "编辑器", Url = "/Adm/Demo/Editor", Type = 2, Order = 24, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demoAdv.Id, Name = "表单验证", Url = "/Adm/Demo/FormValidate", Type = 2, Order = 25, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demoAdv.Id, Name = "图表", Url = "/Adm/Demo/Chart", Type = 2, Order = 26, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demoAdv.Id, Name = "图表-Morris", Url = "/Adm/Demo/ChartMorris", Type = 2, Order = 27, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demoAdv.Id, Name = "ChartJs", Url = "/Adm/Demo/ChartJs", Type = 2, Order = 28, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demoAdv.Id, Name = "表格", Url = "/Adm/Demo/DataTable", Type = 2, Order = 29, CreateDateTime = now
                },
                new MenuEntity {
                    ParentId = demoAdv.Id, Name = "高级表格", Url = "/Adm/Demo/DataTableAdv", Type = 2, Order = 30, CreateDateTime = now
                }
            };
            demoMenus.ForEach(x => x.Create());
            menus.AddRange(demoMenus);

            #endregion

            #region 角色

            var superAdminRole = new RoleEntity {
                Name = "超级管理员", Description = "超级管理员"
            };
            var guestRole = new RoleEntity {
                Name = "guest", Description = "游客"
            };
            List <RoleEntity> roles = new List <RoleEntity>
            {
                superAdminRole,
                guestRole
            };
            roles.ForEach(x => x.Create());

            #endregion

            #region 用户角色关系

            List <UserRoleEntity> userRoles = new List <UserRoleEntity>
            {
                new UserRoleEntity {
                    UserId = admin.Id, RoleId = superAdminRole.Id
                },
                new UserRoleEntity {
                    UserId = guest.Id, RoleId = guestRole.Id
                }
            };
            userRoles.ForEach(x => x.Create());

            #endregion

            #region 角色菜单权限关系
            //超级管理员授权/游客授权
            List <RoleMenuEntity> roleMenus = new List <RoleMenuEntity>();
            var len = menus.Count;
            for (int i = 0; i < len; i++)
            {
                var menuId = menus[i].Id;
                roleMenus.Add(new RoleMenuEntity {
                    RoleId = superAdminRole.Id, MenuId = menuId
                });
                roleMenus.Add(new RoleMenuEntity {
                    RoleId = guestRole.Id, MenuId = menuId
                });
            }

            roleMenus.ForEach(x => x.Create());

            #endregion

            AddOrUpdate(context, m => m.User, user.ToArray());

            AddOrUpdate(context, m => new { m.ParentId, m.Name, m.Type }, menus.ToArray());

            AddOrUpdate(context, m => m.Name, roles.ToArray());

            AddOrUpdate(context, m => new { m.UserId, m.RoleId }, userRoles.ToArray());

            AddOrUpdate(context, m => new { m.MenuId, m.RoleId }, roleMenus.ToArray());
        }
Esempio n. 30
0
        public string SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
        {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();

            //判断角色
            if (LoginInfo.RoleId.StartsWith("C_"))
            {
                //获取当前用户创建的站点数量
                List <UserEntity> item = service.FindList(ExtLinq.True <UserEntity>().And(t => t.F_CreatorUserId.Contains(LoginInfo.UserId)).And(t => t.F_RoleId.StartsWith("S")));
                if (item.Count < LoginInfo.AuthorizationQuantity)
                {
                    if (!string.IsNullOrEmpty(keyValue))
                    {
                        userEntity.Modify(keyValue);
                        UserEntity user = service.FindEntity(c => c.F_Id == keyValue);
                        userEntity.F_CreatorTime = user.F_CreatorTime;

                        //超级管理员 || 系统管理员
                        if (LoginInfo.RoleId.EndsWith("_admin"))
                        {
                            if (!userEntity.F_AuthorizationDays.IsEmpty())
                            {
                                userEntity.F_ExpireTime    = ((DateTime)userEntity.F_CreatorTime).AddDays(userEntity.F_AuthorizationDays);
                                userEntity.F_DaysRemaining = userEntity.F_AuthorizationDays;
                            }
                        }
                        service.SubmitForm(userEntity, userLogOnEntity, keyValue);
                        return("修改完成");
                    }
                    else
                    {
                        userEntity.Create();
                        if (userEntity.F_RoleId.StartsWith("A_"))
                        {
                        }
                        else if (userEntity.F_RoleId.StartsWith("C_"))
                        {
                            userEntity.F_CompanyId = LoginInfo.UserId;
                        }
                        else if (userEntity.F_RoleId.StartsWith("S_"))
                        {
                            userEntity.F_StationId = userEntity.F_Id;
                            userEntity.F_CompanyId = LoginInfo.CompanyId;
                        }
                        else
                        {
                            userEntity.F_StationId = userEntity.F_StationId;
                            userEntity.F_CompanyId = LoginInfo.CompanyId;
                        }
                        userEntity.F_ExpireTime = DateTime.Now;
                        //超级管理员 || 系统管理员
                        if (LoginInfo.RoleId.EndsWith("_admin"))
                        {
                            if (!userEntity.F_AuthorizationDays.IsEmpty())
                            {
                                userEntity.F_ExpireTime    = ((DateTime)userEntity.F_CreatorTime).AddDays(userEntity.F_AuthorizationDays);
                                userEntity.F_DaysRemaining = userEntity.F_AuthorizationDays;
                            }
                        }
                        service.SubmitForm(userEntity, userLogOnEntity, keyValue);
                        return("创建完成");
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(keyValue))
                    {
                        userEntity.Modify(keyValue);
                        UserEntity user = service.FindEntity(c => c.F_Id == keyValue);
                        userEntity.F_CreatorTime = user.F_CreatorTime;
                        userEntity.F_ExpireTime  = DateTime.Now;
                        //超级管理员 || 系统管理员
                        if (LoginInfo.RoleId.EndsWith("_admin"))
                        {
                            if (!userEntity.F_AuthorizationDays.IsEmpty())
                            {
                                if (0 != userEntity.F_AuthorizationDays)
                                {