Esempio n. 1
0
        public async Task <JsonResult> ChangeNickName([FromServices] INickNameProvider nicknameProvider, string name)
        {
            bool success;

            name = Regex.Replace(name, @"\s+", string.Empty);
            var ret = CheckNickName(name);

            if (ret.Value != null)
            {
                return(ret);
            }
            UserProfile user = _db.Users.SingleOrDefault(u => u.UserName == User.Identity.Name);

            var result = await _expUtil.trySpendPointAsync(User.Identity.Name, 200);

            int points = result.Item2;

            if (result.Item1 == false)
            {
                success = false;
            }
            else
            {
                user.NickName = name;
                await _db.SaveChangesAsync();

                nicknameProvider.UpdateNickNameCache(user);
                success = true;
            }
            return(Json(new { success = success, points = points }));
        }
Esempio n. 2
0
        public async Task <JsonResult> ChangeTitle([FromServices] INickNameProvider nicknameProvider, UserQuest.UserProfession?title)
        {
            if (!title.HasValue)
            {
                return(Json(new { success = false }));
            }
            var user = await GetCurrentUserAsync();

            if (user.quest == null || !user.quest.HasTitle(title.Value))
            {
                return(Json(new { success = false }));
            }
            user.quest.Title = title.Value;
            var result = await _userManager.UpdateAsync(user);

            nicknameProvider.UpdateNickNameCache(user);
            return(Json(new { success = result.Succeeded, current = user.quest.Title.ToString() }));
        }