예제 #1
0
        public async Task <IActionResult> PostMemberInfoAsync([FromHeader] String source,
                                                              [FromRoute] RouteIdInt route,
                                                              [FromBody] MemberInfoPost item)
        {
            var response = new Response <Object>();

            try {
                if (await _IMemberInfoRepository.IsExistAsync(a => a.MemberId == route.id && a.IsEnable == 1))
                {
                    var entity = await _IMemberInfoRepository.FirstOrDefaultAsync(a => a.MemberId == route.id);

                    if (!string.IsNullOrEmpty(item.NickName))
                    {
                        entity.NickName = item.NickName;
                    }
                    if (item.Sex.HasValue)
                    {
                        entity.Sex = item.Sex;
                    }
                    if (!string.IsNullOrEmpty(item.Phone))
                    {
                        entity.Phone = item.Phone;
                    }
                    if (!string.IsNullOrEmpty(item.Name))
                    {
                        entity.Name = item.Name;
                    }
                    if (!string.IsNullOrEmpty(item.Alipay))
                    {
                        entity.Alipay = item.Alipay;
                        await _ITaskInfoApp.AddTasks("T0004", new TaskItem()
                        {
                            MemberId  = entity.MemberId,
                            InvitedId = 0,
                            FromMark  = 0
                        });
                    }
                    //注销账号
                    entity.IsEnable = item.IsEnable;//注销
                    _IMemberInfoRepository.Update(entity);
                    response.Code = await _IMemberInfoRepository.SaveChangesAsync() > 0;

                    response.Message = "修改成功";
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex) {
                response.SetError(ex, this._ILogger);
            }
            return(response.ToHttpResponse());
        }
예제 #2
0
        public async Task <IActionResult> PostUserRegisterAsync([FromHeader] String source,
                                                                [FromHeader] String authorization,
                                                                [FromBody] RegisterPost item)
        {
            var response = new Response <JwtAuthorData>();
            var message  = string.Empty;

            try {
                var entity = await _IMemberInfosRepository.FirstOrDefaultAsync(a => a.Uid == item.uid && a.OpenId == item.openid && a.IsEnable == 1);

                if (entity == null)
                {
                    entity             = new MemberInfos();
                    entity.Code        = SnowFlake.GetInstance().GetUniqueShortId(8);
                    entity.NickName    = item.name;
                    entity.Name        = item.name;
                    entity.Sex         = item.gender == "男" ? 1 : 0;
                    entity.Avatar      = item.iconurl;
                    entity.Uid         = item.uid;
                    entity.OpenId      = item.openid;
                    entity.Phone       = item.phone;
                    entity.Password    = Tools.Md5("000000");
                    entity.Beans       = 0;
                    entity.BeansTotals = 0;

                    entity.NewsNumber      = 0;
                    entity.FollowNumber    = 0;
                    entity.FavoritesNumber = 0;
                    entity.FansNumber      = 0;

                    entity.IsNoviceTask  = 0;
                    entity.IsEnable      = 1;
                    entity.LastLoginTime = System.DateTime.Now;
                    entity.CreateTime    = System.DateTime.Now;
                    entity.Remarks       = "微信首次登录注册。";

                    await _IMemberInfosRepository.AddAsync(entity);

                    await _IMemberInfosRepository.SaveChangesAsync();

                    message = "初始登录密码为【000000】";

                    var taskNoviceLogs = await _ITaskInfoRepository.Query(a => a.IsNoviceTask == 1 && a.IsEnable == 1)
                                         .Select(a => new TaskNoviceLog()
                    {
                        TaskId        = a.TaskId,
                        CategoryFixed = a.CategoryFixed,
                        CategoryDay   = a.CategoryDay,
                        MemberId      = entity.MemberId,
                        IsEnable      = 1
                    })
                                         .ToListAsync();

                    await _ITaskNoviceLogRepository.BatchAddAsync(taskNoviceLogs);
                }
                else
                {
                    message = "已注册,初始登录密码为【000000】";
                }
                var result = _IJwtRedis.Create(entity);
                if (result != null)
                {
                    //await _IJwtRedis.DeactivateAsync(authorization);
                    response.Code    = true;
                    response.Message = message;
                    response.Data    = result;
                }
                else
                {
                    return(BadRequest("授权失败!"));
                }
            }
            catch (Exception ex) {
                response.SetError(ex, this._ILogger);
            }
            return(response.ToHttpResponse());
        }