Пример #1
0
        public async Task <string> PersonalInfo([FromForm] PersonalInfo model)
        {
            BaseResult baseResult = new BaseResult();

            try
            {
                int iUserId = Convert.ToInt32(User.Claims.FirstOrDefault(x => x.Type == "Id")?.Value);
                if (iUserId > 0)
                {
                    UserInfo entityUserInfo = await _userInfoService.GetUserInfoAsync(new UserInfo()
                    {
                        Id = iUserId
                    });

                    if (entityUserInfo != null)
                    {
                        if (model != null)
                        {
                            PersonalInfoValidation validationRules  = new PersonalInfoValidation();
                            ValidationResult       validationResilt = await validationRules.ValidateAsync(model);

                            if (validationResilt.IsValid)
                            {
                                entityUserInfo.SuserName  = model.SuserName;
                                entityUserInfo.SuserEmail = model.SuserEmail;
                                entityUserInfo.SuserPhone = model.SuserPhone;
                                if (!string.IsNullOrWhiteSpace(model.Uid.ToString()))
                                {
                                    UploadFileInfo entityUploadFileInfo = await _uploadFileInfoService.GetFileInfoAsync(new UploadFileInfo()
                                    {
                                        Uid = model.Uid
                                    });

                                    if (entityUploadFileInfo != null)
                                    {
                                        entityUserInfo.IfileInfoId = entityUploadFileInfo.Id;
                                    }
                                }
                                if (!string.IsNullOrWhiteSpace(model.SoldPassWord) && !string.IsNullOrWhiteSpace(model.SnewPassWord) && !string.IsNullOrWhiteSpace(model.SconfirmPassWord))
                                {
                                    //判断旧密码是否正确
                                    if (await _userInfoService.CheckUserAsync(entityUserInfo.SloginName, model.SoldPassWord) != null)
                                    {
                                        entityUserInfo.SloginPwd = model.SconfirmPassWord;
                                        //修改密码
                                        _userInfoService.ChangeUserPassWord(entityUserInfo, User.Identity.Name);
                                        baseResult.Code = 0;
                                        baseResult.Msg  = "修改成功!";
                                        await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
                                    }
                                    else
                                    {
                                        baseResult.Code = 4;
                                        baseResult.Msg  = "旧密码错误!";
                                    }
                                }
                                else
                                {
                                    await _userInfoService.AddOrModifyUserInfoAsync(_mapper.Map <AddOrModifyUserInfo>(entityUserInfo), User.Identity.Name);

                                    baseResult.Code = 0;
                                    baseResult.Msg  = "修改成功!";
                                }
                            }
                            else
                            {
                                baseResult.Code = 3;
                                baseResult.Msg  = validationResilt.ToString("<br>");
                            }
                        }
                    }
                    else
                    {
                        baseResult.Code = 2;
                        baseResult.Msg  = "未知错误!";
                    }
                }
            }
            catch (Exception ex)
            {
                baseResult.Code = 4;
                baseResult.Msg  = ex.Message;
            }
            return(JsonHelper.ObjectToJSON(baseResult));
        }