Ejemplo n.º 1
0
        /// <summary>
        /// handler=Ajax
        /// </summary>
        /// <param name="mpId"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public async Task <IActionResult> OnGetAjaxAsync(int mpId = 0, int pageIndex = 1, int pageSize = 10)
        {
            MpAccountDto mpAccountDto = null;// new MpAccountDto();

            if (mpId > 0)
            {
                var mpAccount = await _mpAccountService.GetObjectAsync(z => z.Id == mpId);

                if (mpAccount == null)
                {
                    return(RenderError("公众号配置不存在:" + mpId));
                }
                mpAccountDto = _mpAccountService.Mapper.Map <MpAccountDto>(mpAccount);
            }

            var seh = new Ncf.Utility.SenparcExpressionHelper <Models.WeixinUser>();

            seh.ValueCompare.AndAlso(mpAccountDto != null, z => z.MpAccountId == mpAccountDto.Id);
            var where = seh.BuildWhereExpression();
            var result = await _weixinUserService.GetObjectListAsync(pageIndex, pageSize, where,
                                                                     z => z.Id, Ncf.Core.Enums.OrderingType.Descending, z => z.Include(p => p.UserTags_WeixinUsers).ThenInclude(p => p.UserTag));

            //ViewData["Test"] = result.FirstOrDefault();
            var weixinUserDtos = new PagedList <WeixinUserDto>(result.Select(z => _weixinUserService.Mapper.Map <WeixinUserDto>(z)).ToList(), result.PageIndex, result.PageCount, result.TotalCount);

            return(Ok(new { mpAccountDto, weixinUserDtos = new { weixinUserDtos.TotalCount, list = weixinUserDtos.Select(_ => new
                    {
                        _.AddTime,
                        _.Remark,
                        _.AdminRemark,
                        _.City,
                        _.Country,
                        _.Groupid,
                        _.HeadImgUrl,
                        _.Id,
                        _.Language,
                        _.LastUpdateTime,
                        _.MpAccountId,
                        _.NickName,
                        _.OpenId,
                        _.Province,
                        _.Qr_Scene,
                        _.Qr_Scene_Str,
                        _.Sex,
                        _.Subscribe,
                        _.Subscribe_Scene,
                        Subscribe_Time = new DateTime(1970, 1, 1).AddSeconds(_.Subscribe_Time).ToString(),
                        //_.Tagid_List,
                        _.UnionId,
                        UserTags_WeixinUsers = _.UserTags_WeixinUsers.Select(__ => new { __.UserTag, __.UserTagId, __.WeixinUserId }),
                    }).AsEnumerable() } }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGetSyncUserAsync(int mpId)
        {
            var mpAccount = await _mpAccountService.GetObjectAsync(z => z.Id == mpId);

            if (mpAccount == null)
            {
                return(RenderError("公众号配置不存在:" + mpId));
            }

            //List<WeixinUserDto> weixinUserDtos = new List<WeixinUserDto>();
            string lastOpenId = null;

            while (true)
            {
                var result = await Senparc.Weixin.MP.AdvancedAPIs.UserApi.GetAsync(mpAccount.AppId, lastOpenId);

                if (result.data != null)
                {
                    foreach (var openId in result.data.openid)
                    {
                        var user = await Senparc.Weixin.MP.AdvancedAPIs.UserApi.InfoAsync(mpAccount.AppId, openId);

                        var weixinUser = await _weixinUserService.GetObjectAsync(z => z.OpenId == openId);

                        var weixinUserDto = _weixinUserService.Mapper.Map <WeixinUser_UpdateFromApiDto>(user);
                        weixinUserDto.MpAccountId = mpId;
                        if (weixinUser != null)
                        {
                            //TODO:判断并更新 特定的DTO对象
                            //weixinUserDto.Id = weixinUser.Id;
                        }
                        else
                        {
                            //TODO:更新group和tag信息
                            weixinUser = _weixinUserService.Mapper.Map <Models.WeixinUser>(weixinUserDto);
                            await _weixinUserService.SaveObjectAsync(weixinUser);
                        }
                    }
                }

                if (result.next_openid.IsNullOrEmpty())
                {
                    break;
                }
                lastOpenId = result.next_openid;
            }
            base.SetMessager(Scf.Core.Enums.MessageType.success, "更新成功!");
            return(RedirectToPage("./Index", new { uid = Uid, mpId = mpId }));
        }
        public async Task <IActionResult> OnGetAsync(int id = 0)
        {
            IsEdit = id > 0;
            if (IsEdit)
            {
                var mpAccount = await _mpAccountService.GetObjectAsync(z => z.Id == id);

                if (mpAccount == null)
                {
                    return(RenderError("公众号信息不存在!"));
                }

                MpAccountDto = _mpAccountService.Mapper.Map <MpAccountDto>(mpAccount);
            }
            else
            {
                MpAccountDto = new MpAccountDto();
            }
            return(Page());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnGetAsync(int mpId = 0, int pageIndex = 1)
        {
            if (mpId > 0)
            {
                var mpAccount = await _mpAccountService.GetObjectAsync(z => z.Id == mpId);

                if (mpAccount == null)
                {
                    return(RenderError("公众号配置不存在:" + mpId));
                }
                MpAccountDto = _mpAccountService.Mapper.Map <MpAccountDto>(mpAccount);
            }

            var seh = new Scf.Utility.SenparcExpressionHelper <Models.WeixinUser>();

            seh.ValueCompare.AndAlso(MpAccountDto != null, z => z.MpAccountId == MpAccountDto.Id);
            var where = seh.BuildWhereExpression();
            var result = await _weixinUserService.GetObjectListAsync(pageIndex, pageCount, where, z => z.Id, Scf.Core.Enums.OrderingType.Descending);

            WeixinUserDtos = new PagedList <WeixinUserDto>(result.Select(z => _mpAccountService.Mapper.Map <WeixinUserDto>(z)).ToList(), result.PageIndex, result.PageCount, result.TotalCount);
            return(Page());
        }
        public async Task <IActionResult> OnPostDeleteAsync(int[] ids)
        {
            foreach (var id in ids)
            {
                var mpAccount = await _mpAccountService.GetObjectAsync(z => z.Id == id);

                if (mpAccount != null)
                {
                    await _mpAccountService.DeleteObjectAsync(mpAccount);

                    await AccessTokenContainer.RemoveFromCacheAsync(mpAccount.AppId);//Çå³ý×¢²á״̬
                }
            }
            return(RedirectToPage("./Index", new { Uid }));
        }
        public async Task <IActionResult> OnPostDeleteAsync(int[] ids)
        {
            var mpId = 0;

            foreach (var id in ids)
            {
                var weixinUser = await _weixinUserService.GetObjectAsync(z => z.Id == id);

                if (weixinUser != null)
                {
                    mpId = weixinUser.MpAccountId;
                    await _weixinUserService.DeleteObjectAsync(weixinUser);
                }
            }
            return(RedirectToPage("./Index", new { Uid, mpId }));
        }