Esempio n. 1
0
        private int AddSysWeChatConfigNode(AccountManage model, MpAppAddView addMpAppView)
        {
            SysWechatConfig sysView = new SysWechatConfig()
            {
                AccountManageId      = model.Id,
                AppName              = model.AccountName,
                CreatedDate          = DateTime.Now,
                CreatedUserID        = User.Identity.Name,
                WeixinToken          = addMpAppView.WeixinToken,
                WeixinEncodingAESKey = addMpAppView.WeixinEncodingAESKey,
                WeixinAppId          = addMpAppView.WeixinAppId,
                WeixinCorpId         = addMpAppView.WeixinAppId,
                WeixinCorpSecret     = addMpAppView.WeixinCorpSecret,
                IsCorp = model.AccountType == 0,
            };

            _Logger.Debug("Create SysConfigView:  {0}", sysView);
            _wechatConfigService.Repository.Insert(sysView);
            int mainMenuId = sysView.Id;

            return(mainMenuId);
        }
Esempio n. 2
0
        public ActionResult AddAccountManages(MpAppAddView addMpAppView)
        {
            if (!ModelState.IsValid)
            {
                StringBuilder builder   = new StringBuilder();
                var           errorList = ModelState.Values.Where(a => a.Errors.Count > 0).ToList();
                foreach (var error in errorList)
                {
                    foreach (var item in error.Errors)
                    {
                        builder.Append(item.ErrorMessage).Append("</br>");
                    }
                }
                throw new Exception(builder.ToString());
            }

            try
            {
                AccountManageView accountManageView = new AccountManageView()
                {
                    CorpId             = addMpAppView.WeixinAppId,
                    AccountName        = addMpAppView.AccountName,
                    AccountDescription = addMpAppView.AccountDescription,
                    AccountLogo        = addMpAppView.AccountLogo,
                    QrCode             = addMpAppView.QrCode,
                    AccountType        = addMpAppView.AccountType,
                };
                AccountManage model = _accountManageService.Add(accountManageView);
                if (accountManageView.AccountLogo.ContentLength > 0)
                {
                    //获得保存路径
                    string newName  = "AccountLogo" + model.Id.ToString() + accountManageView.AccountLogo.FileName.ToString().Substring(accountManageView.AccountLogo.FileName.ToString().IndexOf("."));
                    string filePath = Path.Combine(HttpContext.Server.MapPath("~/"), "Content/picture",
                                                   Path.GetFileName(newName));
                    accountManageView.AccountLogo.SaveAs(filePath);
                    string resoucePath = Path.Combine(("/Content/picture"), Path.GetFileName(newName));
                    model.AccountLogo = resoucePath.Replace("\\", "/");
                }

                if (accountManageView.QrCode.ContentLength > 0)
                {
                    //获得保存路径
                    string newName  = "AccountQrCode" + model.Id.ToString() + accountManageView.QrCode.FileName.ToString().Substring(accountManageView.QrCode.FileName.ToString().IndexOf("."));
                    string filePath = Path.Combine(HttpContext.Server.MapPath("~/"), "Content/picture",
                                                   Path.GetFileName(newName));
                    accountManageView.QrCode.SaveAs(filePath);
                    string resoucePath = Path.Combine(("/Content/picture"), Path.GetFileName(newName));
                    model.QrCode = resoucePath.Replace("\\", "/");
                }
                _accountManageService.Update(model);
                //在SysWeCahtConfig 表中添加企业小助手(企业号) 或 服务号名称(服务号)的APP,WeixinAppid = 0, 为了让企业号可以load 出来
                int wechatid = AddSysWeChatConfigNode(model, addMpAppView);
                //在Menu表中添加AccountManageID 列, 用来标记, Infrastructure.Web.Domain.dll
                //查找AccountManage在Menu 中的节点的条件为: ParentId=0 && AccountManageID = AccountManageID
                //添加Menu节点信息, 并生成Default Menu
                AddMenuNodeForAccountManagement(model, wechatid);

                var list = FilterAccountManageByUser();
                list = list.Where(a => a.AccountType == accountManageView.AccountType).ToList();

                return(Json(new { result = 200 }));
            }
            catch (Exception e)
            {
                _Logger.Debug("Add New MP APP Error:", e);
                return(Json(new { result = 400, message = e }));
                //throw e;
            }
        }