Exemplo n.º 1
0
        public bool EditUser(RoadFlow.Data.Model.Users user)
        {
            if (user.Mobile.IsNullOrEmpty() && user.Email.IsNullOrEmpty() && user.WeiXin.IsNullOrEmpty())
            {
                return(false);
            }
            if (GetUser(user.Account).IsNullOrEmpty())
            {
                return(AddUser(user));
            }
            string url = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=" + GetAccessToken();
            List <RoadFlow.Data.Model.UsersRelation> allByUserID = new UsersRelation().GetAllByUserID(user.ID);

            RoadFlow.Platform.Organize organize = new RoadFlow.Platform.Organize();
            StringBuilder stringBuilder         = new StringBuilder();

            foreach (RoadFlow.Data.Model.UsersRelation item in allByUserID)
            {
                RoadFlow.Data.Model.Organize organize2 = organize.Get(item.OrganizeID);
                if (organize2 != null)
                {
                    stringBuilder.Append(organize2.IntID);
                    stringBuilder.Append(",");
                }
            }
            string   text     = "{\"userid\":\"" + user.Account + "\",\"name\":\"" + replaceName(user.Name) + "\",\"department\":[" + stringBuilder.ToString().TrimEnd(',') + "],\"position\":\"\",\"mobile\":\"" + user.Mobile + "\"," + (user.Sex.HasValue ? ("\"gender\":\"" + (user.Sex.Value + 1).ToString() + "\",") : "") + "\"email\":\"" + user.Email + "\",\"weixinid\":\"" + user.WeiXin + "\",\"enable\":" + ((user.Status == 0) ? 1 : 0).ToString() + "}";
            string   text2    = HttpHelper.SendPost(url, text);
            JsonData jsonData = JsonMapper.ToObject(text2);
            bool     flag     = jsonData.ContainsKey("errcode") && jsonData["errcode"].ToString().ToInt() == 0;

            Log.Add("调用了微信修改人员-" + user.Name + "-" + (flag ? "成功" : "失败"), "返回:" + text2, Log.Types.微信企业号, user.Serialize(), text);
            return(flag);
        }
Exemplo n.º 2
0
        public void Subscribe(UserDto publisher, UserDto subscriber)
        {
            if (publisher == null || subscriber == null)
            {
                throw new ArgumentNullException();
            }
            if (publisher.Id == 0)
            {
                throw new DtoValidationException("Publisher Id is not set");
            }
            if (subscriber.Id == 0)
            {
                throw new DtoValidationException("Subscriber Id is not set");
            }
            if (publisher.Id == subscriber.Id)
            {
                throw new DtoValidationException("Publisher and Subscriber are same people!");
            }

            ExecuteNonQuery(unitOfWork =>
            {
                User publisherFromDb = unitOfWork.UserRepository.GetById(publisher.Id);
                if (publisherFromDb == null)
                {
                    throw new DomainModelException("No such publisher");
                }

                User subscriberFromDb = unitOfWork.UserRepository.GetById(subscriber.Id);
                if (subscriberFromDb == null)
                {
                    throw new DomainModelException("No such subscriber");
                }

                UsersRelation usersRelation = new UsersRelation()
                {
                    PublisherId  = publisher.Id,
                    SubscriberId = subscriber.Id
                };
                unitOfWork.UsersRelationRepository.Create(usersRelation);
                unitOfWork.SaveChanges();
            });
        }
Exemplo n.º 3
0
        public static UsersRelation SubscribeAt(this User u, User u2)
        {
            if (u.Subscriptions is null)
            {
                u.Subscriptions = new List <UsersRelation>();
            }
            if (u2.Subscribers is null)
            {
                u2.Subscribers = new List <UsersRelation>();
            }
            UsersRelation ur = new UsersRelation()
            {
                Id           = ++_userRelationsCounter,
                Publisher    = u2,
                PublisherId  = u2.Id,
                Subscriber   = u,
                SubscriberId = u.Id
            };

            u.Subscriptions.Add(ur);
            u2.Subscribers.Add(ur);
            return(ur);
        }
Exemplo n.º 4
0
        public void UpdateAllUsers()
        {
            RoadFlow.Platform.Organize organize  = new RoadFlow.Platform.Organize();
            UsersRelation usersRelation          = new UsersRelation();
            List <RoadFlow.Data.Model.Users> all = new Users().GetAll();
            DataTable dataTable = new DataTable
            {
                Columns =
                {
                    {
                        "姓名",
                        "".GetType()
                    },
                    {
                        "帐号",
                        "".GetType()
                    },
                    {
                        "微信号",
                        "".GetType()
                    },
                    {
                        "手机号",
                        "".GetType()
                    },
                    {
                        "邮箱",
                        "".GetType()
                    },
                    {
                        "所在部门",
                        "".GetType()
                    },
                    {
                        "职位",
                        "".GetType()
                    }
                }
            };

            foreach (RoadFlow.Data.Model.Users item in all)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (RoadFlow.Data.Model.UsersRelation item2 in usersRelation.GetAllByUserID(item.ID))
                {
                    RoadFlow.Data.Model.Organize organize2 = organize.Get(item2.OrganizeID);
                    if (organize2 != null)
                    {
                        stringBuilder.Append(organize2.IntID);
                        stringBuilder.Append(",");
                    }
                }
                DataRow dataRow = dataTable.NewRow();
                dataRow["姓名"]   = replaceName(item.Name);
                dataRow["帐号"]   = item.Account;
                dataRow["微信号"]  = item.WeiXin;
                dataRow["手机号"]  = item.Mobile;
                dataRow["邮箱"]   = item.Email;
                dataRow["所在部门"] = stringBuilder.ToString().TrimEnd(',');
                dataRow["职位"]   = "";
                dataTable.Rows.Add(dataRow);
            }
            string text = Files.FilePath + "WeiXinCsv\\";

            if (!Directory.Exists(text))
            {
                Directory.CreateDirectory(text);
            }
            string text2 = text + Guid.NewGuid().ToString("N") + ".csv";

            NPOIHelper.ExportCSV(dataTable, text2);
            string text3 = new Media(Config.GetSecret("weixinagents_organize")).UploadTemp(text2, "file");

            if (!text3.IsNullOrEmpty())
            {
                string url   = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser?access_token=" + GetAccessToken();
                string text4 = "{\"media_id\":\"" + text3 + "\"}";
                string str   = HttpHelper.SendPost(url, text4);
                Log.Add("调用了微信同步所有人员", "返回:" + str, Log.Types.微信企业号, text4);
            }
        }