public ActionResult Add(AppUserInfo data)
        {
            data.RoleNames = appUserDAL.GetAllUserRoles();
            if (ModelState.IsValid)
            {
                try
                {
                    if (db.Users.Any(w => w.Username.ToLower() == data.Username.ToLower()))
                    {
                        TempData["ErrorMessage"] = "This username is taken. Please choose other one";
                        return(View(data));
                    }
                    else
                    {
                        User _user = new User
                        {
                            Username  = data.Username,
                            Password  = mainDAL.CalculateMD5Hash(data.Password),
                            Role_ID   = data.Role_ID,
                            IsDeleted = false
                        };
                        db.Users.Add(_user);
                        db.SaveChanges();
                        TempData["InfoMessage"] = "New user has been successfully added";
                        return(RedirectToAction("Preview"));
                    }
                }
                catch (Exception ex)
                {
                    string message = ex.InnerException != null ? "Message: " + ex.Message + Environment.NewLine + "InnerException: " + ex.InnerException.Message : "Message: " + ex.Message;
                    mainDAL.RecordInLogger("ERROR", "Add User", message, "", "");
                    TempData["ErrorMessage"] = "Some error happens and the user is not added. Contact the Admin.";
                    return(View(data));
                }
            }

            return(View(data));
        }
Example #2
0
        /// <summary>
        /// 推送事件(穿透消息)
        /// </summary>
        /// <param name="notifyEvent"></param>
        private void pushEvent(SeatManage.JsonModel.JM_NotifyEvent notifyEvent)
        {
            try
            {
                AppUserInfo app_user = AMS.ServiceProxy.App_UserInfoProxy.GetAppUserInfoByCardNoAndSchoolNum(notifyEvent.CardNo, notifyEvent.SchoolNum);
                if (app_user == null)
                {
                    return;
                }
                if (notifyEvent == null)
                {
                    return;
                }
                PushOptions pOpts = new PushOptions(app_user.ChannelId, 0, SeatManage.SeatManageComm.JSONSerializer.Serialize(notifyEvent), null, api_key, getTimestamp(), null, Device_Type.Android);

                BaiduPush.BaiduPush push = new BaiduPush.BaiduPush("POST", secret_key);
                string pushResult        = push.PushSingleDevice(pOpts);
                //  SeatManage.SeatManageComm.WriteLog.Write("消息推送结果:" + pushResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public bool Auth(string appID, string timestamp, string sign, out string errorMsg)
        {
            if (string.IsNullOrEmpty(appID))
            {
                errorMsg = "缺少认证参数[appid]";
                return(false);
            }
            if (string.IsNullOrEmpty(timestamp))
            {
                errorMsg = "缺少认证参数[timestamp]";
                return(false);
            }
            if (string.IsNullOrEmpty(sign))
            {
                errorMsg = "缺少认证参数[sign]";
                return(false);
            }
            AppUserInfo appUserInfo = AppUserManager.Create().Get(appID);

            if (appUserInfo == null)
            {
                errorMsg = "无效的[appid]";
                return(false);
            }
            string input     = string.Format("appid={0}&secretkey={1}&timestamp={2}", appID, appUserInfo.AppSecret, timestamp);
            string checksign = CryptographyManager.Md5Encrypt(input);

            if (string.Compare(sign, checksign, true) != 0)
            {
                errorMsg = "认证方式错误";
                return(false);
            }

            errorMsg = "";
            return(true);
        }
Example #4
0
 public Feedback SaveUser([FromBody] AppUserInfo data, string tenant = "")
 {
     return(_userProvider.GetInstance(tenant).saveUser(tenant, data));
 }
Example #5
0
        public Feedback saveUser(string tenant, AppUserInfo data)
        {
            Feedback feedback = new Feedback();

            try
            {
                AppNotification notification;
                if (data.notificationid == 0)
                {
                    notification = new AppNotification()
                    {
                        type     = _userRepo.GetInstance(tenant).tableName,
                        message  = "Saving data",
                        progress = 0
                    };
                    _notificationRepo.GetInstance(tenant).save(ref notification);
                    _hubContext.Clients.All.SendAsync("SendNotification", notification);
                }
                else
                {
                    notification = _notificationRepo.GetInstance(tenant).getById(data.notificationid);
                }
                try
                {
                    using (var transaction = DBServer.BeginTransaction())
                    {
                        if (_userRepo.GetInstance(tenant).saveUser(ref data, transaction))
                        {
                            transaction.Commit();
                            notification.progress = 1;
                            notification.message  = "Data saved sucessfully for User: "******"SendNotification", notification);
                            feedback = new Feedback
                            {
                                Code    = 1,
                                Message = "Data saved sucessfully",
                                data    = data
                            };
                        }
                        else
                        {
                            transaction.Commit();
                            notification.progress = 1;
                            notification.message  = "Data saved sucessfully";
                            notification.recordId = data.USID;
                            _notificationRepo.GetInstance(tenant).save(ref notification);
                            _hubContext.Clients.All.SendAsync("SendNotification", notification);
                            feedback = new Feedback
                            {
                                Code    = 1,
                                Message = "Data saved sucessfully",
                                data    = data
                            };
                        }
                    }
                }
                catch (Exception ex)
                {
                    notification.progress = -1;
                    notification.message  = "Got the error while removing data";
                    _notificationRepo.GetInstance(tenant).save(ref notification);
                    _hubContext.Clients.All.SendAsync("SendNotification", notification);
                    feedback = new Feedback
                    {
                        Code    = 0,
                        Message = "Got the error while removing data",
                        data    = ex
                    };
                    GitHub.createIssue(ex, new { tenant = tenant, data = data }, _accessor.HttpContext.Request.Headers);
                }
            }
            catch (Exception ex)
            {
                GitHub.createIssue(ex, new { tenant = tenant, data = data }, _accessor.HttpContext.Request.Headers);
            }
            return(feedback);
        }
Example #6
0
 public MyUserStore(AppUserInfo appUserInfo)
 {
     _userService = new AuthApi(appUserInfo);
 }
        /// <summary>
        /// </summary>
        /// 微信登录回调
        public void WXLoginBack()
        {
            Client     customer    = new Client();
            WeiXinUser weiXinUser  = WeiXinService.GetWeiXinUser(string.Empty, Request.Params["code"].ToString());
            string     callbackUrl = Request.QueryString["state"].ToString();

            if (weiXinUser != null && !string.IsNullOrEmpty(weiXinUser.Openid))
            {
                Client cusomerInfo = ClientService.LoadClientByAppCustomerID(weiXinUser.Openid);
                if (cusomerInfo != null && cusomerInfo.SysNo > 0)
                {
                    //更新用户头像以及昵称
                    cusomerInfo.Name        = weiXinUser.NickName;
                    cusomerInfo.HeaderImage = weiXinUser.HeadImgUrl;
                    cusomerInfo.EditTime    = DateTimeHelper.GetTimeZoneNow();

                    ClientService.UpdateClient(cusomerInfo);

                    var appuser = new AppUserInfo()
                    {
                        AppCustomerID   = weiXinUser.Openid,
                        UserSysNo       = cusomerInfo.SysNo,
                        UserID          = HttpUtility.UrlEncode(cusomerInfo.Name),
                        HeadImage       = cusomerInfo.HeaderImage,
                        UserDisplayName = HttpUtility.UrlEncode(cusomerInfo.Name),

                        ManagerSysNo      = cusomerInfo.ManagerSysNo,
                        UserType          = UserType.Common,
                        LastLoginDateText = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"),
                        ManagerLoginName  = cusomerInfo.ManagerLoginName,
                        ManagerName       = HttpUtility.UrlEncode(cusomerInfo.ManagerName)
                    };

                    if (cusomerInfo.ManagerSysNo.HasValue && cusomerInfo.ManagerSysNo.Value > 0)
                    {
                        appuser.UserType = UserType.Manager;
                        var company = CompanyService.GetCompanyUser(cusomerInfo.ManagerSysNo.Value);
                        if (company != null)
                        {
                            appuser.UserType = UserType.Installer;
                        }
                    }

                    UserMgr.Logout();
                    UserMgr.WriteUserInfo(appuser);
                    if (!string.IsNullOrEmpty(callbackUrl))
                    {
                        Response.Redirect(callbackUrl);
                        return;
                    }
                    Response.Redirect("/smoke/userInfo");
                    return;
                }
                else//新建client
                {
                    customer.AppCustomerID = weiXinUser.Openid;
                    customer.Name          = weiXinUser.NickName;
                    customer.HeaderImage   = weiXinUser.HeadImgUrl;
                    customer.EditTime      = DateTimeHelper.GetTimeZoneNow();
                    customer.RegisterTime  = DateTimeHelper.GetTimeZoneNow();
                    //创建用户
                    customer.SysNo = ClientService.InsertClient(customer);
                    var appuser = new AppUserInfo()
                    {
                        AppCustomerID     = weiXinUser.Openid,
                        UserSysNo         = customer.SysNo,
                        UserID            = HttpUtility.UrlEncode(customer.Name),
                        UserDisplayName   = HttpUtility.UrlEncode(customer.Name),
                        HeadImage         = customer.HeaderImage,
                        UserType          = UserType.Common,
                        LastLoginDateText = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss")
                    };
                    UserMgr.Logout();
                    UserMgr.WriteUserInfo(appuser);
                    if (!string.IsNullOrEmpty(callbackUrl))
                    {
                        Response.Redirect(callbackUrl);
                        return;
                    }
                    Response.Redirect("/smoke/userInfo");
                    return;
                }
            }
        }
 protected void LoadCurrentUser()
 {
     AppUserInfo = CurrentUser.GetCurrentUserInfo();
 }
Example #9
0
 public AuthApi(AppUserInfo appUserInfo) : base(appUserInfo)
 {
     _unitOfWork = new UnitOfWork(new IdentityContext("DefaultConnection"));
 }
Example #10
0
 public IsNotEqualCurrentUser(AppUserInfo currentUser)
 {
     _currentUser = currentUser;
 }
Example #11
0
 protected BaseApi(AppUserInfo appUserInfo)
 {
     AppUserInfo = appUserInfo;
 }
 private void CurrentUserOnChange(AppUserInfo user)
 {
     SetUserAccess(user);
 }
        private void InitializeApplication()
        {
            try
            {
                #region  Machine Standard Pattern
                // Essential
                U.RootComp.Add(new DefaultLogger(AppConstStaticName.DEFAULT_LOGGER));
                // Force load of certain references
                Type ty = typeof(SMFlowChartCtlBasic);
                //Machine
                ComponentDefinition machineDef = new ComponentDefinition(typeof(AppMachine.Comp.AppMachine), AppConstStaticName.APP_MACHINE);
                //Essential add Machine to Root

                #endregion

                #region Standard Machine Common Param Pattern
                U.RootComp.Add(new AppCommonParam(AppConstStaticName.COMMON_PARAMETER));
                #endregion

                #region Station Standard Pattern
                //Station
                CompBase stations = new CompBase(AppConstStaticName.ALL_STATIONS);
                #endregion

                //Station Define

                /*Add New Station Here (Example in Below)
                 * stations.Add(new AppFeederStation(AppConstStaticName.FEEDSTATION));
                 * stations.Add(new AppVisionStation(AppConstStaticName.VISIONSTATION));
                 */

                stations.Add(new AppStationBase("Sample Station"));

                #region Station Standard Pattern
                U.RootComp.Add(stations, CompRoot.eCleanUpMode.AllLayer);
                #endregion


                //IO System Define
                //Add IO Component Here (Example in Below)
                //ComponentDefinition ioSystem = new ComponentDefinition(IOSystemBase.PlugIns.ModbusTcpIO, AppConstStaticName.ALL_IO);
                ComponentDefinition ioSystem = new ComponentDefinition(typeof(IOSystemBase), "ModbusTcpIO", AppConstStaticName.ALL_IO);
                Inputs inputsIO            = new Inputs(AppConstStaticName.INPUTS);
                ComponentDefinition inputs = ioSystem.Add(inputsIO);


                //Inputs List Define

                /* Add IO Component Here (Example in Below)
                 * inputs.Add(new AppSafetyInput(AppConstStaticName.STARTPB) { Channel = 0 });//X1
                 * inputs.Add(new AppSafetyInput(AppConstStaticName.STOPPB) { Channel = 1 });//X2
                 * inputs.Add(new AppSafetyInput(AppConstStaticName.RESETPB) { Channel = 2 });//X3
                 */


                Outputs             outputsIO = new Outputs(AppConstStaticName.OUTPUTS);
                ComponentDefinition outputs   = ioSystem.Add(outputsIO);

                //Outputs List Define

                /*
                 * outputs.Add(new BoolOutput(AppConstStaticName.REDLIGHT) { Channel = 0 });
                 * outputs.Add(new BoolOutput(AppConstStaticName.AMBERLIGHT) { Channel = 1 });
                 * outputs.Add(new BoolOutput(AppConstStaticName.GREENLIGHT) { Channel = 2 });
                 * outputs.Add(new BoolOutput(AppConstStaticName.BUZZER) { Channel = 3 });
                 */

                try
                {
                    U.RootComp.Add(ioSystem, CompRoot.eCleanUpMode.AllLayer);
                }
                catch (Exception ex)
                {
                    U.LogPopup(ex, "IO System Initialize Unsuccessful in loading of application");
                }



                //Vision System Define

                /* Add Vision Conponent Here (Example in Below)
                 * //Vision
                 * ComponentDefinition visionSys = machineDef.Add(VisionSystemBase.PlugIns.Cognex9, AppConstStaticName.VISIONSYSTEM);
                 * ComponentDefinition camAOI = visionSys.Add(CameraBase.PlugIns.CognexCamera9, AppConstStaticName.VISIONCAMERA);
                 * ComponentDefinition aoiJob = camAOI.Add(VisionJobBase.PlugIns.CognexJob9, AppConstStaticName.VISIONJOB);
                 * aoiJob.Add(new AppVisionAOIResult(AppConstStaticName.VISIONJOBRESULT));
                 */



                //Motion System Define

                /* Add Motion Conponent Here (Example in Below)
                 *
                 * //Feed Motion
                 * ComponentDefinition feedMotionSys = machineDef.Add(MotionSystemBase.PlugIns.YamahaTrServo, AppConstStaticName.FEEDMOTIONSYSTEM);
                 * ComponentDefinition feedMotionAxes = feedMotionSys.Add(new AppRealAxes(AppConstStaticName.FEEDMOTIONAXES));
                 * ComponentDefinition feedYAxis = feedMotionAxes.Add(new AppRealAxis(AppConstStaticName.FEEDYAXIS) { AxisNo = 0, MaxLimit = 75, MinLimit = 0, DefaultSpeed = 70.0, AccelDecel = 100.0 });
                 *
                 * //Lift1 Motion
                 * ComponentDefinition lift1MotionSys = machineDef.Add(MotionSystemBase.PlugIns.IAIScon, AppConstStaticName.LIFT1MOTIONSYSTEM);
                 * ComponentDefinition lift1MotionAxes = lift1MotionSys.Add(new AppRealAxes(AppConstStaticName.LIFT1MOTIONAXES));
                 * ComponentDefinition lift1ZAxis = lift1MotionAxes.Add(new AppRealAxis(AppConstStaticName.LIFT1ZAXIS) { AxisNo = 0, MaxLimit = 75, MinLimit = 0, DefaultSpeed = 70.0, AccelDecel = 0.1  });
                 *
                 * //Lift2 Motion
                 * ComponentDefinition lift2MotionSys = machineDef.Add(MotionSystemBase.PlugIns.IAIScon, AppConstStaticName.LIFT2MOTIONSYSTEM);
                 * ComponentDefinition lift2MotionAxes = lift2MotionSys.Add(new AppRealAxes(AppConstStaticName.LIFT2MOTIONAXES));
                 * ComponentDefinition lift2ZAxis = lift2MotionAxes.Add(new AppRealAxis(AppConstStaticName.LIFT2ZAXIS) { AxisNo = 0, MaxLimit = 75, MinLimit = 0, DefaultSpeed = 70.0, AccelDecel = 0.1 });
                 */


                #region State Machine Standard Pattern
                //Define Stae Machine Component
                ComponentDefinition smDef = new ComponentDefinition(typeof(CompBase), AppConstStaticName.ALL_STATE_MACHINE);

                smDef.Add(new SMStateMachine(AppConstStaticName.SM_RESET));
                smDef.Add(new SMStateMachine(AppConstStaticName.SM_MAIN));
                #endregion

                //State Machine Define

                /* Add New State Machine Here (Example in Below)
                 * smDef.Add(new SMStateMachine(AppConstStaticName.SM_FEED));
                 * smDef.Add(new SMStateMachine(AppConstStaticName.SM_VISION));
                 */


                #region State Semi-Auto Machine Standard Pattern
                //Define Stae Machine Component
                ComponentDefinition smSemiAutoDef = new ComponentDefinition(typeof(CompBase), AppConstStaticName.ALL_SEMI_AUTO_STATE_MACHINE);
                smSemiAutoDef.Add(new SMStateMachine(AppConstStaticName.SM_SEMI_RESET));
                smSemiAutoDef.Add(new SMStateMachine(AppConstStaticName.SM_SEMI_MAIN));
                #endregion

                //Semi State Machine Define

                /* Add New State Machine Here (Example in Below)
                 * smSemiAutoDef.Add(new SMStateMachine(AppConstStaticName.SM_SEMI_FEED));
                 * smSemiAutoDef.Add(new SMStateMachine(AppConstStaticName.SM_SEMI_VISION));
                 */


                #region State Machine Standard Pattern
                U.RootComp.Add(smDef, CompRoot.eCleanUpMode.FirstLayer);
                #endregion

                #region Semi Auto State Machine Standard Pattern
                U.RootComp.Add(smSemiAutoDef, CompRoot.eCleanUpMode.FirstLayer);
                #endregion

                #region Recipe Standard Pattern
                ComponentDefinition recipeDef = new ComponentDefinition(typeof(CompBase), AppConstStaticName.ALL_RECIPES);
                recipeDef.Add(new AppProductRecipe(AppConstStaticName.REF_CURRENT_RECIPE));
                recipeDef.Add(new AppProductRecipe(AppConstStaticName.SAMPLE_RECIPE));
                U.RootComp.Add(recipeDef);
                #endregion

                #region User Standard Pattern
                ComponentDefinition users     = new ComponentDefinition(typeof(CompBase), AppConstStaticName.ALL_USER);
                AppUserInfo         adminUser = new AppUserInfo(AppConstStaticName.ADMIN_USER)
                {
                    UserEN = "00000", UserCode = "00000", UserLevel = Comp.AppEnums.eAccessLevel.Supervisor
                };
                users.Add(adminUser);
                AppUserInfo guestUser = new AppUserInfo(AppConstStaticName.GUEST_USER)
                {
                    UserEN = "00001", UserCode = "00001", UserLevel = Comp.AppEnums.eAccessLevel.Operator
                };
                users.Add(adminUser);
                users.Add(guestUser);

                U.RootComp.Add(users);
                #endregion

                #region Standard Pattern

                try
                {
                    //Add machine to root comp after add all components belong to the machine.
                    U.RootComp.Add(machineDef);
                    AppMachine.Comp.AppMachine.This.IOList.Initialize();
                }
                catch (Exception ex)
                {
                    U.LogPopup(ex, "Machine Initialize Unsuccessful in loading of application");
                }


                // Essential call after all component definitions
                U.RootComp.InitializeIDReferences();

                this.BeginInvoke((MethodInvoker) delegate
                {
                    _mainPanel.RebuildCompBrowser();


                    // //State Machine Instance with bind to control
                    GetSMInstanceWithBindControl();


                    // //Semi Auto State Machine Instance with bind to control
                    GetSMSemiAutoInstanceWithBindControl();


                    //Initiate User
                    if (AppMachine.Comp.AppMachine.This.CurrentUser == null)
                    {
                        AppMachine.Comp.AppMachine.This.CurrentUser = U.GetComponent(AppConstStaticName.ADMIN_USER) as AppUserInfo;
                    }

                    //Prepare Stop When Finish
                    mcbStopWhenFinished.DataBindings.Add("Checked", AppMachine.Comp.AppMachine.This, "StopWhenFinished");

                    //Prepare All Panel
                    _mainPanel.PrepareAllPanel();


                    //Update Operation Button
                    UpdateControlButtons();

                    //Set User Access for Current User
                    SetUserAccess(AppMachine.Comp.AppMachine.This.CurrentUser);
                });


                U.RegisterOnChanged(() => AppMachine.Comp.AppMachine.This.CurrentUser, CurrentUserOnChange);

                AppMachine.Comp.AppMachine.This.LoadStartupRecipe();
                VerifyCriticalSimulateComponent();
                _mainPanel.RegisterMachineStatusEvent();
                #endregion
            }

            #region Standard Pattern
            catch (Exception ex)
            {
                U.LogPopup(ex + " " + ex.StackTrace, "Unsuccessful in loading of application");
            }
            finally
            {
                this.BeginInvoke((MethodInvoker) delegate
                {
                    _splashThread.Abort();
                });
            }
            #endregion


            #region Auto Lockout Standard Pattern
            _autoLockoutTimer.Interval = 500;
            _autoLockoutTimer.Elapsed += new System.Timers.ElapsedEventHandler(AutoLockoutTimer_OnElapse);
            _autoLockoutTimer.Enabled  = true;
            #endregion
        }
 public AuthApi(AppUserInfo appUserInfo) : base(appUserInfo)
 {
 }
Example #15
0
        public ActionResult BindingAdminID(string ID, string password)
        {
            if (string.IsNullOrWhiteSpace(ID) || string.IsNullOrWhiteSpace(password))
            {
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "请输入账号和密码!"
                }));
            }
            string pd = SecurityHelper.GetMD5Value(password);

            #region 【验证账号有效性】
            SystemUser result = AuthDA.LoadSystemUserByIDAndPassword(ID, pd, ConstValue.ApplicationID);
            if (result == null)
            {
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "账号或密码错误!"
                }));
            }
            if (result.CommonStatus != CommonStatus.Actived)
            {
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "账号已被禁用,请联系您的管理员。"
                }));
            }
            if (result.MasterSysNo == null || result.MasterSysNo <= 0)
            {
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "不存在此账号。"
                }));
            }
            #endregion

            Client user = ClientService.LoadClient(curentUser.UserSysNo);
            if (user == null)
            {
                UserMgr.Logout();
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "登录超时,请退出公众号重新进行。"
                }));
            }

            #region 【绑定后台账号到client】
            user.ManagerSysNo = result.SysNo;
            ClientService.UpdateClient(user);
            #endregion

            #region 【更新cookie】

            Company company = CompanyService.GetCompanyUser(result.SysNo);
            if (company != null && company.SysNo > 0)
            {
                curentUser.UserType = UserType.Installer;
            }
            else
            {
                curentUser.UserType = UserType.Manager;
            }
            AppUserInfo loginUser = curentUser;
            loginUser.ManagerSysNo     = result.SysNo;
            loginUser.ManagerLoginName = result.LoginName;
            loginUser.ManagerName      = HttpUtility.UrlEncode(result.UserFullName);
            UserMgr.Logout();
            UserMgr.WriteUserInfo(loginUser);

            #endregion

            return(Json(new AjaxResult()
            {
                Success = true, Message = "绑定成功!"
            }));
        }
Example #16
0
        protected override void Seed(AppDbContext context)
        {
            var tenant = context.Admin_Tenants.FirstOrDefault(p => p.IsSystemTenant);

            if (tenant == null)
            {
                tenant = new Admin_Tenant {
                    IsSystemTenant = true, Name = "系统租户", Remark = "系统租户,勿删!"
                };
                context.Admin_Tenants.Add(tenant);
                context.SaveChanges();
            }

            #region 添加用户和角色

            //全局管理员多租户Id为1
            var store = new AppUserStore(context)
            {
                TenantId = tenant.Id
            };
            var userManager = new UserManager <AppUser, string>(store);
            var roleManager = new RoleManager <AppRole>(new AppRoleStore(context));
            //系统管理员
            var adminRole = new AppRole
            {
                Id          = "{74ABBD8D-ED32-4C3A-9B2A-EB134BFF5D91}",
                Name        = "Admin",
                Description = "超级管理员,拥有最大权限"
            };
            if (!roleManager.RoleExists(adminRole.Name))
            {
                roleManager.Create(adminRole);
            }
            //租户管理员
            var tenantManager = new AppRole
            {
                Id          = "{EB715DD5-1EEF-4131-B6B1-0DAE2FAA8861}",
                Name        = "TenantManager",
                Description = "租户管理员"
            };
            if (!roleManager.RoleExists(tenantManager.Name))
            {
                roleManager.Create(tenantManager);
            }
            //店铺管理员
            var shopManager = new AppRole
            {
                Id          = "{80BAB54E-856E-4DBE-85E1-A5F819BF9622}",
                Name        = "ShopManager",
                Description = "店铺管理员"
            };
            if (!roleManager.RoleExists(shopManager.Name))
            {
                roleManager.Create(shopManager);
            }
            //店铺小二
            var shopWater = new AppRole
            {
                Id          = "{F77E3025-026F-44DA-8565-18B1018E88F8}",
                Name        = "ShopWater",
                Description = "店铺小二"
            };
            if (!roleManager.RoleExists(shopWater.Name))
            {
                roleManager.Create(shopWater);
            }

            var user = new AppUser
            {
                Id             = "{B0FBB2AC-3174-4E5A-B772-98CF776BD4B9}",
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                TenantId       = tenant.Id
            };
            if (!userManager.Users.Any(p => p.Id == user.Id))
            {
                var result = userManager.Create(user, "123456abcD");
                if (result.Succeeded)
                {
                    userManager.AddToRole(user.Id, adminRole.Name);
                }
            }

            #endregion

            #region 初始化菜单

            if (!context.Site_Menus.Any())
            {
                var menus      = new List <Site_Menu>();
                var menuWeChat = MenuDataSeedHelper.CreateRootMenu("微信功能管理", "", "", "", "fa fa-weixin");
                menus.Add(menuWeChat);

                #region 自定义菜单

                var menu1 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "菜单管理", "", "", "", "fa fa-th-large");
                menus.Add(menu1);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu1.Id, "自定义菜单", "Index", "Menus", "/Menus", ""));

                #endregion

                #region 粉丝管理

                var menu2 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "粉丝管理", "", "", "", "fa fa-users");
                menus.Add(menu2);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu2.Id, "粉丝管理", "Index", "WeiChat_User", "/WeiChat_User",
                                                             ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu2.Id, "用户组管理", "Index", "WeiChat_UserGroup",
                                                             "/WeiChat_UserGroup", ""));

                #endregion

                #region  材管理

                var menu3 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "素材管理", "", "", "", "fa fa-file-image-o");
                menus.Add(menu3);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "图片管理", "Index", "Site_Resources",
                                                             "/Site_Resources?resourceType=0", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "语音管理", "Index", "Site_Resources",
                                                             "/Site_Resources?resourceType=1", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "视频管理", "Index", "Site_Resources",
                                                             "/Site_Resources?resourceType=2", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "图文消息管理", "Index", "Site_News", "/Site_News", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "文章管理", "Index", "Site_Article", "/Site_Article",
                                                             ""));

                #endregion

                #region 消息管理

                var menu4 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "消息管理", "", "", "", "fa  fa-comments-o");
                menus.Add(menu4);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "文本推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=0", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "图片推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=1", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "语音推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=3", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "视频推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=4", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "图文推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=5", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "模板消息", "Index", "WeiChat_MessagesTemplate",
                                                             "/WeiChat_MessagesTemplate", ""));

                #endregion

                #region 场景二维码

                var menu5 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "场景二维码", "", "", "", "fa fa-qrcode");
                menus.Add(menu5);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu5.Id, "二维码管理", "Index", "WeiChat_QRCode",
                                                             "/WeiChat_QRCode", ""));

                #endregion

                #region 客服管理

                var menu6 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "客服管理", "", "", "", "fa fa-users");
                menus.Add(menu6);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu6.Id, "客服管理", "Index", "WeiChat_KFCInfo",
                                                             "/WeiChat_KFCInfo", ""));

                #endregion

                #region 智能回复

                var menu7 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "智能回复", "", "", "", "fa fa-slack");
                menus.Add(menu7);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu7.Id, "关键字回复", "Index", "WeiChat_KeyWordAutoReply",
                                                             "/WeiChat_KeyWordAutoReply", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu7.Id, "关注时回复", "Index", "WeiChat_SubscribeReply",
                                                             "/WeiChat_SubscribeReply", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu7.Id, "答不上来配置", "Index", "WeiChat_NotAnswerReply",
                                                             "/WeiChat_NotAnswerReply", ""));

                #endregion

                #region 数据与统计

                var menu8 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "数据与统计", "", "", "", "fa fa-line-chart");
                menus.Add(menu8);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu8.Id, "关键字回复统计", "Index", "WeiChat_KeyWordReplyLog",
                                                             "/WeiChat_KeyWordReplyLog", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu8.Id, "位置统计", "Index", "WeiChat_LocationEventLog",
                                                             "/WeiChat_LocationEventLog", ""));

                #endregion

                //var menu1 = MenuDataSeedHelper.CreateRootMenu(title: "菜单管理", action: "", controller: "", url: "", iconCls: "fa fa-th-large");
                //menus.Add(menu1);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu1.Id, title: "自定义菜单", action: "Index", controller: "Menus", url: "/Menus", iconCls: ""));

                //var menu2 = MenuDataSeedHelper.CreateRootMenu(title: "粉丝管理", action: "", controller: "", url: "", iconCls: "fa fa-users");
                //menus.Add(menu2);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu2.Id, title: "粉丝管理", action: "Index", controller: "WeiChat_User", url: "/WeiChat_User", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu2.Id, title: "用户组管理", action: "Index", controller: "WeiChat_UserGroup", url: "/WeiChat_UserGroup", iconCls: ""));

                //var menu3 = MenuDataSeedHelper.CreateRootMenu(title: "素材管理", action: "", controller: "", url: "", iconCls: "fa fa-file-image-o");
                //menus.Add(menu3);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "图片管理", action: "Index", controller: "Site_Resources", url: "/Site_Resources?resourceType=0", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "语音管理", action: "Index", controller: "Site_Resources", url: "/Site_Resources?resourceType=1", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "视频管理", action: "Index", controller: "Site_Resources", url: "/Site_Resources?resourceType=2", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "图文消息管理", action: "Index", controller: "Site_News", url: "/Site_News", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "文章管理", action: "Index", controller: "Site_Article", url: "/Site_Article", iconCls: ""));

                //var menu4 = MenuDataSeedHelper.CreateRootMenu(title: "消息管理", action: "", controller: "", url: "", iconCls: "fa  fa-comments-o");
                //menus.Add(menu4);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "文本推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=0", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "图片推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=1", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "语音推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=3", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "视频推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=4", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "图文推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=5", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "模板消息", action: "Index", controller: "WeiChat_MessagesTemplate", url: "/WeiChat_MessagesTemplate", iconCls: ""));

                //var menu5 = MenuDataSeedHelper.CreateRootMenu(title: "场景二维码", action: "", controller: "", url: "", iconCls: "fa fa-qrcode");
                //menus.Add(menu5);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu5.Id, title: "二维码管理", action: "Index", controller: "WeiChat_QRCode", url: "/WeiChat_QRCode", iconCls: ""));

                //var menu6 = MenuDataSeedHelper.CreateRootMenu(title: "客服管理", action: "", controller: "", url: "", iconCls: "fa fa-users");
                //menus.Add(menu6);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu6.Id, title: "客服管理", action: "Index", controller: "WeiChat_KFCInfo", url: "/WeiChat_KFCInfo", iconCls: ""));

                //var menu7 = MenuDataSeedHelper.CreateRootMenu(title: "智能回复", action: "", controller: "", url: "", iconCls: "fa fa-slack");
                //menus.Add(menu7);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu7.Id, title: "关键字回复", action: "Index", controller: "WeiChat_KeyWordAutoReply", url: "/WeiChat_KeyWordAutoReply", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu7.Id, title: "关注时回复", action: "Index", controller: "WeiChat_SubscribeReply", url: "/WeiChat_SubscribeReply", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu7.Id, title: "答不上来配置", action: "Index", controller: "WeiChat_NotAnswerReply", url: "/WeiChat_NotAnswerReply", iconCls: ""));

                //var menu8 = MenuDataSeedHelper.CreateRootMenu(title: "数据与统计", action: "", controller: "", url: "", iconCls: "fa fa-line-chart");
                //menus.Add(menu8);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu8.Id, title: "关键字回复统计", action: "Index", controller: "WeiChat_KeyWordReplyLog", url: "/WeiChat_KeyWordReplyLog", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu8.Id, title: "位置统计", action: "Index", controller: "WeiChat_LocationEventLog", url: "/WeiChat_LocationEventLog", iconCls: ""));

                //var menu9 = MenuDataSeedHelper.CreateRootMenu(title: "系统设置", action: "", controller: "", url: "", iconCls: "fa fa-cogs");
                //menus.Add(menu9);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu9.Id, title: "微信支付设置", action: "Index", controller: "WeiChat_PayConfig", url: "/WeiChat_PayConfig", iconCls: ""));


                context.Site_Menus.AddRange(menus);
                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    var str = "";
                    foreach (var item in ex.EntityValidationErrors)
                    {
                        foreach (var eitem in item.ValidationErrors)
                        {
                            str += eitem.PropertyName + ":" + eitem.ErrorMessage;
                        }
                    }
                    throw new Exception(str);
                }
                //初始化角色菜单
                if (!context.Role_Menus.Any(p => p.RoleId == adminRole.Id))
                {
                    foreach (var item in menus)
                    {
                        context.Role_Menus.Add(new Role_Menu
                        {
                            MenuId = item.Id,
                            RoleId = adminRole.Id
                        });
                    }
                    context.SaveChanges();
                }
            }

            #endregion

            #region 初始化默认相册
            if (context.Site_PhotoGallerys.Find(new Guid("6FAC25BF-DBE1-423D-93C8-FB31D98D8F72")) == null)
            {
                var photoGallery = new Site_PhotoGallery
                {
                    Id         = new Guid("6FAC25BF-DBE1-423D-93C8-FB31D98D8F72"),
                    Title      = "首页滚动图片相册",
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Site_PhotoGallerys.Add(photoGallery);
                context.SaveChanges();
            }
            #endregion

            #region 初始化商品标签
            //精品排行标签
            if (context.Product_Tags.Find(new Guid("527BD456-2411-4BAB-A67B-4760752D7198")) == null)
            {
                var jpphTag = new Product_Tag
                {
                    Id         = new Guid("527BD456-2411-4BAB-A67B-4760752D7198"),
                    Name       = "精品排行",
                    IsSystem   = true,
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Product_Tags.Add(jpphTag);
            }
            //新品促销标签
            if (context.Product_Tags.Find(new Guid("A2587E2F-B1ED-4F24-A089-4201E40780C5")) == null)
            {
                var xpcxTag = new Product_Tag
                {
                    Id         = new Guid("A2587E2F-B1ED-4F24-A089-4201E40780C5"),
                    Name       = "新品促销",
                    IsSystem   = true,
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Product_Tags.Add(xpcxTag);
            }
            //热门推荐标签
            if (context.Product_Tags.Find(new Guid("D8970F09-6C1B-429D-8E33-EC16AC90BC11")) == null)
            {
                var rmtjTag = new Product_Tag
                {
                    Id         = new Guid("D8970F09-6C1B-429D-8E33-EC16AC90BC11"),
                    Name       = "热门推荐",
                    IsSystem   = true,
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Product_Tags.Add(rmtjTag);
            }
            #endregion
            #region 初始化默认广告位
            if (context.Advert_Types.Find(new Guid("6FAC25BF-DBE1-423D-93C8-FB31D98D8F72")) == null)
            {
                var advertType = new Advert_Type
                {
                    Id         = new Guid("6FAC25BF-DBE1-423D-93C8-FB31D98D8F72"),
                    Name       = "首页滚动图片广告位置",
                    IsSystem   = true,
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Advert_Types.Add(advertType);
                context.SaveChanges();
            }
            #endregion
            #region 添加WeiChat_User
            if (!context.WeiChat_Users.Any())
            {
                var weichatuser = new WeiChat_User
                {
                    OpenId        = "o3Q4xv9pXYCBk-pdpvgqWTbs8aLY",
                    Subscribe     = true,
                    NickName      = "差不多先生",
                    Sex           = WeChat.SDK.Apis.User.WeChatSexTypes.Man,
                    City          = "linfen",
                    Country       = "中国",
                    Province      = "山西",
                    Language      = "zh_CN",
                    HeadImgUrl    = "http://wx.qlogo.cn/mmopen/rycTXpWzibw2l9v7TNN0uFGcjQzHCic6tcOy8dLLnkPTZdP7rZxsSXXQCRJRjoXpKWhkRXnOol544kE6S5Of6uRg/0",
                    UnionId       = "1",
                    Remark        = "9054",
                    GroupIds      = "102",
                    AllowTest     = false,
                    TenantId      = 1,
                    SubscribeTime = DateTime.Parse("2016 - 11 - 24 08:58:56.000")
                };
                context.WeiChat_Users.Add(weichatuser);
                context.SaveChanges();
            }
            #endregion
            #region 添加AppUserInfo
            if (!context.AppUserInfos.Any(p => p.OpenId == "o3Q4xv9pXYCBk - pdpvgqWTbs8aLY"))
            {
                var appUserInfo = new AppUserInfo
                {
                    //Id = new Guid(),
                    UserNo           = 1,
                    OpenId           = "o3Q4xv9pXYCBk - pdpvgqWTbs8aLY",
                    Member_loginname = "bb",
                    Member_password  = "******",
                    Nick_name        = "bb",
                    Member_ID        = 5,
                    Real_Name        = "我靠",
                    Empiric_Num      = 1,
                    Gold_Num         = 100,
                    Balance          = 100,
                    ServiceShop_ID   = 5,
                    Member_img       = new Guid(),
                    Sex        = Enumusersexs.男,
                    School_ID  = 2,
                    Birth_Date = DateTime.Now,
                    Status     = EnumUserStates.Normal,
                    TenantId   = 0,
                    CreateTime = DateTime.Now
                };
                context.AppUserInfos.Add(appUserInfo);
                context.SaveChanges();
            }
            #endregion
            #region 创建学校跟学院
            if (!context.User_Schools.Any())
            {
                var user_School1 = new User_School
                {
                    School_Name    = "中北大学",
                    ParentID       = 0,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_School2 = new User_School
                {
                    School_Name    = "山西大学",
                    ParentID       = 0,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_School3 = new User_School
                {
                    School_Name    = "太原理工大学",
                    ParentID       = 0,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_campus1 = new User_School
                {
                    School_Name    = "土木工程学院",
                    ParentID       = user_School1.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_campus2 = new User_School
                {
                    School_Name    = "软件工程学院",
                    ParentID       = user_School1.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_campus3 = new User_School
                {
                    School_Name    = "环境工程学院",
                    ParentID       = user_School1.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_campus4 = new User_School
                {
                    School_Name    = "人文学院",
                    ParentID       = user_School1.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };

                var user_campus5 = new User_School
                {
                    School_Name    = "软件学院",
                    ParentID       = user_School2.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                context.User_Schools.Add(user_campus5);
                var user_campus6 = new User_School
                {
                    School_Name    = "土木工程学院",
                    ParentID       = user_School2.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                context.User_Schools.Add(user_campus1); context.User_Schools.Add(user_campus2); context.User_Schools.Add(user_campus3); context.User_Schools.Add(user_campus4); context.User_Schools.Add(user_campus5); context.User_Schools.Add(user_campus6); context.User_Schools.Add(user_School3); context.User_Schools.Add(user_School2); context.User_Schools.Add(user_School1);
                context.SaveChanges();
            }
            #endregion
        }