Esempio n. 1
0
        public async Task <IActionResult> Index(int?id)
        {
            var avatarList = (await _staticAvatarService.GetAvartarListAsync()).ToList();

            if (avatarList.Count() > 0)
            {
                if (id.HasValue)
                {
                    if (!avatarList.Any(_ => _.Id == id.Value))
                    {
                        id = null;
                    }
                }

                var user = await _userService.GetDetails(GetActiveUserId());

                var viewingAvatarId = id ?? user.AvatarId ?? avatarList.FirstOrDefault().Id;
                var avatar          = avatarList.FirstOrDefault(_ => _.Id == viewingAvatarId);
                avatar.Filename = _pathResolver.ResolveContentPath(avatar.Filename);

                var currentIndex = avatarList.FindIndex(_ => _.Id == viewingAvatarId);
                int previousAvatarId;
                int nextAvatarId;
                if (currentIndex == 0)
                {
                    previousAvatarId = avatarList.Last().Id;
                }
                else
                {
                    previousAvatarId = avatarList[currentIndex - 1].Id;
                }

                if (currentIndex == avatarList.Count - 1)
                {
                    nextAvatarId = avatarList.First().Id;
                }
                else
                {
                    nextAvatarId = avatarList[currentIndex + 1].Id;
                }

                AvatarSelectionViewModel viewModel = new AvatarSelectionViewModel()
                {
                    Avatar           = avatarList.FirstOrDefault(_ => _.Id == viewingAvatarId),
                    PreviousAvatarId = previousAvatarId,
                    NextAvatarId     = nextAvatarId
                };

                return(View(viewModel));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(AvatarSelectionViewModel model)
        {
            try
            {
                var avatar = await _staticAvatarService.GetByIdAsync(model.Avatar.Id);

                var user = await _userService.GetDetails(GetActiveUserId());

                user.AvatarId = avatar.Id;
                await _userService.Update(user);

                AlertSuccess = "Your avatar has been updated";
                return(RedirectToAction("Index", "Home"));
            }
            catch (GraException gex)
            {
                AlertInfo = gex.Message;
                return(RedirectToAction("Index"));
            }
        }