Esempio n. 1
0
        /// <summary>
        /// 修改用户昵称
        /// </summary>
        public async Task <int> ModifyNickNameAsync(ProfileInfoEditModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            model.NickName = model.NickName.Trim();
            Guid?id = this.httpContextAccessor.HttpContext.User.GetUserId();

            if (id == null)
            {
                throw new Exception("用户未登录");
            }
            using (var work = this.dbFactory.StartWork())
            {
                Person dbPerson = await work.Person.SingleByIdAsync(id.Value);

                if (string.Equals(dbPerson.NickName, model.NickName, StringComparison.OrdinalIgnoreCase) || string.Equals(dbPerson.AccountName, model.NickName, StringComparison.OrdinalIgnoreCase))
                {
                    return(await work.Person.ModifyNickNameAsync(dbPerson.Id, model.NickName));
                }
                else
                {
                    if (await work.Person.IsExistNameAsync(model.NickName))
                    {
                        throw new ModelException(nameof(model.NickName), "该昵称已存在,请重新输入");
                    }
                    return(await work.Person.ModifyNickNameAsync(dbPerson.Id, model.NickName));
                }
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Info()
        {
            PersonView person = await this.personService.GetCurrentPersonViewAsync();

            ProfileInfoEditModel model = new ProfileInfoEditModel()
            {
                AccountName = person.AccountName, NickName = person.NickName
            };

            return(View(model));
        }
Esempio n. 3
0
        public async Task <IActionResult> Info(ProfileInfoEditModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await this.personService.ModifyNickNameAsync(model);

                    return(this.Json(AjaxResult.CreateDefaultSuccess()));
                }
                catch (ModelException ex)
                {
                    return(this.Json(ex.ToAjaxResult()));
                }
                catch (Exception ex)
                {
                    return(this.Json(AjaxResult.CreateByMessage(ex.Message, false)));
                }
            }
            else
            {
                return(this.Json(ModelState.ToAjaxResult()));
            }
        }