Exemplo n.º 1
0
        ////[SupportFilter]
        public ActionResult Edit(string id)
        {
            ViewBag.Perm = GetPermission();
            WC_User entity = m_BLL.m_Rep.Find(Convert.ToInt32(id));

            return(View(entity));
        }
Exemplo n.º 2
0
        public virtual async Task <WC_UserModel> GetByIdAsync(object id)
        {
            if (IsExists(id))
            {
                WC_User entity = await m_Rep.GetByIdAsync(id);

                WC_UserModel model = new WC_UserModel();
                model.Id               = entity.Id;
                model.OpenId           = entity.OpenId;
                model.NickName         = entity.NickName;
                model.Sex              = entity.Sex;
                model.Language         = entity.Language;
                model.City             = entity.City;
                model.Province         = entity.Province;
                model.Country          = entity.Country;
                model.HeadImgUrl       = entity.HeadImgUrl;
                model.SubscribeTime    = entity.SubscribeTime;
                model.UnionId          = entity.UnionId;
                model.Remark           = entity.Remark;
                model.GroupId          = entity.GroupId;
                model.TagidList        = entity.TagidList;
                model.Subscribe        = entity.Subscribe;
                model.OfficalAccountId = entity.OfficalAccountId;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(WC_UserModel model)
        {
            ValidationErrors errors = new ValidationErrors();

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

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity                  = new WC_User();
                entity.Id               = model.Id;
                entity.OpenId           = model.OpenId;
                entity.NickName         = model.NickName;
                entity.Sex              = model.Sex;
                entity.Language         = model.Language;
                entity.City             = model.City;
                entity.Province         = model.Province;
                entity.Country          = model.Country;
                entity.HeadImgUrl       = model.HeadImgUrl;
                entity.SubscribeTime    = model.SubscribeTime;
                entity.UnionId          = model.UnionId;
                entity.Remark           = model.Remark;
                entity.GroupId          = model.GroupId;
                entity.TagidList        = model.TagidList;
                entity.Subscribe        = model.Subscribe;
                entity.OfficalAccountId = model.OfficalAccountId;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }
Exemplo n.º 4
0
        public virtual bool Edit(ref ValidationErrors errors, WC_UserModel model)
        {
            try
            {
                WC_User entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id               = model.Id;
                entity.OpenId           = model.OpenId;
                entity.NickName         = model.NickName;
                entity.Sex              = model.Sex;
                entity.Language         = model.Language;
                entity.City             = model.City;
                entity.Province         = model.Province;
                entity.Country          = model.Country;
                entity.HeadImgUrl       = model.HeadImgUrl;
                entity.SubscribeTime    = model.SubscribeTime;
                entity.UnionId          = model.UnionId;
                entity.Remark           = model.Remark;
                entity.GroupId          = model.GroupId;
                entity.TagidList        = model.TagidList;
                entity.Subscribe        = model.Subscribe;
                entity.OfficalAccountId = model.OfficalAccountId;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Exemplo n.º 5
0
        ////[SupportFilter]
        public JsonResult SyncUser(string id, string officeId)
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                //填充数据
                string[] arrs = id.Split(',');
                List <BatchGetUserInfoData> list = new List <BatchGetUserInfoData>();
                foreach (var m in arrs)
                {
                    list.Add(new BatchGetUserInfoData()
                    {
                        openid = m
                    });
                }

                //批量同步数据
                WC_OfficalAccounts accountModel = account_BLL.m_Rep.Find(Convert.ToInt32(officeId));
                var batchList = Senparc.Weixin.MP.AdvancedAPIs.UserApi.BatchGetUserInfo(accountModel.AccessToken, list);
                foreach (var info in batchList.user_info_list)
                {
                    WC_User userModel = m_BLL.m_Rep.Find(a => a.OpenId == info.openid);
                    if (userModel != null)
                    {
                        userModel.City       = info.city;
                        userModel.OpenId     = info.openid;
                        userModel.OpenId     = info.openid;
                        userModel.HeadImgUrl = info.headimgurl;
                        userModel.Language   = info.language;
                        userModel.NickName   = info.nickname;
                        userModel.Province   = info.province;
                        userModel.Sex        = info.sex.ToString();
                        m_BLL.m_Rep.Update(userModel);
                    }
                }

                LogHandler.WriteServiceLog(GetUserId(), "Ids:" + id, "成功", "删除", "WC_User");
                return(Json(JsonHandler.CreateMessage(1, Resource.SaveSucceed)));
            }
            else
            {
                return(Json(JsonHandler.CreateMessage(0, Resource.SaveFail)));
            }
        }
Exemplo n.º 6
0
 ////[SupportFilter]
 public JsonResult Edit(WC_User model)
 {
     if (model != null)
     {
         if (m_BLL.m_Rep.Update(model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",OpenId" + model.OpenId, "成功", "修改", "WC_User");
             return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",OpenId" + model.OpenId + "," + ErrorCol, "失败", "修改", "WC_User");
             return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
     }
 }
Exemplo n.º 7
0
        ////[SupportFilter(ActionName = "Edit")]
        public ActionResult MoveUser(string userids, string groupid)
        {
            WC_OfficalAccounts wcmodel = account_BLL.GetCurrentAccount();
            List <string>      itemstr = userids.Split(',').ToList();

            foreach (var item in itemstr)
            {
                ViewBag.Perm = GetPermission();
                WC_User model = m_BLL.m_Rep.Find(Convert.ToInt32(item));
                model.GroupId = groupid;
                if (m_BLL.m_Rep.Update(model))
                {
                    LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",OpenId" + model.OpenId, "成功", "修改", "WC_User");
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",OpenId" + model.OpenId + "," + ErrorCol, "失败", "修改", "WC_User");
                    return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
                }
            }
            return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <WC_UserModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        WC_User entity = new WC_User();
                        entity.Id               = ResultHelper.NewId;
                        entity.OpenId           = model.OpenId;
                        entity.NickName         = model.NickName;
                        entity.Sex              = model.Sex;
                        entity.Language         = model.Language;
                        entity.City             = model.City;
                        entity.Province         = model.Province;
                        entity.Country          = model.Country;
                        entity.HeadImgUrl       = model.HeadImgUrl;
                        entity.SubscribeTime    = model.SubscribeTime;
                        entity.UnionId          = model.UnionId;
                        entity.Remark           = model.Remark;
                        entity.GroupId          = model.GroupId;
                        entity.TagidList        = model.TagidList;
                        entity.Subscribe        = model.Subscribe;
                        entity.OfficalAccountId = model.OfficalAccountId;

                        db.WC_User.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 订阅(关注)事件
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            ValidationErrors errors = new ValidationErrors();

            WC_OfficalAccountsBLL account_BLL = new WC_OfficalAccountsBLL();
            //获得当前公众号
            WC_OfficalAccounts account = account_BLL.GetCurrentAccount();
            //将用户提取到本地数据库
            WC_User    userModel = new WC_User();
            WC_UserBLL user_BLL  = new WC_UserBLL();

            account.AccessToken = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetToken(account.AppId, account.AppSecret).access_token;
            UserInfoJson userJson = UserApi.Info(account.AccessToken, requestMessage.FromUserName);

            userModel.OpenId           = userJson.openid;
            userModel.NickName         = userJson.nickname;
            userModel.Sex              = userJson.sex.ToString();
            userModel.Language         = userJson.language;
            userModel.City             = userJson.city;
            userModel.Province         = userJson.province;
            userModel.Country          = userJson.country;
            userModel.HeadImgUrl       = userJson.headimgurl;
            userModel.SubscribeTime    = ResultHelper.GetTimeByLong(userJson.subscribe_time).ToString();
            userModel.UnionId          = userJson.unionid;
            userModel.Remark           = userJson.remark;
            userModel.GroupId          = userJson.groupid.ToString();
            userModel.TagidList        = string.Join(",", userJson.tagid_list.ToArray());
            userModel.Subscribe        = userJson.subscribe.ToString();
            userModel.OfficalAccountId = account.Id.ToString();
            user_BLL.m_Rep.Create(userModel);
            WC_MessageResponseRepository m_Rep = new WC_MessageResponseRepository();
            //订阅回复
            List <WC_MessageResponse> messageList = m_Rep.FindList(a => a.OfficalAccountId == account.Id.ToString() && a.MessageRule == WeChatRequestRuleEnum.Subscriber.ToString() && a.IsDefault == "true").ToList();

            if (messageList.Count() > 0)
            {
                if (messageList[0].Category == WeChatReplyCategory.Text.ToString())
                {
                    var responseMessage = base.CreateResponseMessage <ResponseMessageText>();
                    responseMessage.CreateTime   = ResultHelper.NowTime;
                    responseMessage.ToUserName   = requestMessage.FromUserName;
                    responseMessage.FromUserName = account.OfficalId;
                    responseMessage.Content      = messageList[0].TextContent;
                    return(responseMessage);
                }
                //图文方式
                else if (messageList[0].Category == WeChatReplyCategory.Image.ToString())
                {
                    var responseMessage = CreateResponseMessage <ResponseMessageNews>();
                    foreach (var model in messageList)
                    {
                        responseMessage.Articles.Add(new Article()
                        {
                            Title       = model.TextContent,
                            Description = model.ImgTextContext,
                            PicUrl      = WebChatPara.SiteUrl + model.ImgTextUrl,
                            Url         = model.ImgTextLink
                        });
                    }
                    return(responseMessage);
                }        //一般很少用到
                else if (messageList[0].Category == WeChatReplyCategory.Voice.ToString())
                {
                    var responseMessage = base.CreateResponseMessage <ResponseMessageMusic>();
                    responseMessage.Music.MusicUrl    = WebChatPara.SiteUrl + messageList[0].MeidaUrl;
                    responseMessage.Music.Title       = messageList[0].TextContent;
                    responseMessage.Music.Description = messageList[0].Remark;
                    return(responseMessage);
                }
            }



            var errorResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();

            return(errorResponseMessage);
        }