예제 #1
0
        public async Task <IActionResult> SimplePost(string text, string images, IEnumerable <PollOptionViewModel> pollOptions, SupportedLanguage?language, Guid?gameId)
        {
            UserContentViewModel vm = new UserContentViewModel
            {
                Language = language ?? SupportedLanguage.English,
                Content  = text,
                Poll     = new PollViewModel
                {
                    PollOptions = pollOptions.ToList()
                },
                GameId = gameId
            };

            ProfileViewModel profile = await ProfileAppService.GetByUserId(CurrentUserId, ProfileType.Personal);

            SetAuthorDetails(vm);

            SetContentImages(vm, images);

            OperationResultVo <Guid> result = userContentAppService.Save(CurrentUserId, vm);

            NotifyFollowers(profile, vm.GameId, vm.Id);

            if (EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
            {
                await NotificationSender.SendTeamNotificationAsync("New simple post!");
            }

            return(Json(result));
        }
예제 #2
0
        public async Task <IActionResult> Save(UserContentViewModel vm)
        {
            try
            {
                bool isNew = vm.Id == Guid.Empty;

                ProfileViewModel profile = await ProfileAppService.GetByUserId(CurrentUserId, ProfileType.Personal);

                SetAuthorDetails(vm);

                OperationResultVo <Guid> saveResult = userContentAppService.Save(CurrentUserId, vm);

                if (!saveResult.Success)
                {
                    return(Json(saveResult));
                }
                else
                {
                    NotifyFollowers(profile, vm.GameId, vm.Id);

                    string url = Url.Action("Index", "Home", new { area = string.Empty, id = vm.Id, pointsEarned = saveResult.PointsEarned });

                    if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                    {
                        await NotificationSender.SendTeamNotificationAsync("New complex post!");
                    }

                    return(Json(new OperationResultRedirectVo(url)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
예제 #3
0
        private async Task SetAuthorDetails(GameViewModel vm)
        {
            if (vm.Id == Guid.Empty || vm.UserId == Guid.Empty || vm.UserId == CurrentUserId)
            {
                vm.UserId = CurrentUserId;
                ProfileViewModel profile = await ProfileAppService.GetByUserId(CurrentUserId, ProfileType.Personal);

                if (profile != null)
                {
                    vm.AuthorName    = profile.Name;
                    vm.AuthorPicture = profile.ProfileImageUrl;
                }
            }
        }
예제 #4
0
        public async Task <IActionResult> AnalyseUser(Guid userId)
        {
            AnalyseUserViewModel model = new AnalyseUserViewModel();

            ApplicationUser user = await UserManager.FindByIdAsync(userId.ToString());

            ProfileViewModel profile = await ProfileAppService.GetByUserId(userId, ProfileType.Personal);

            var roles = await UserManager.GetRolesAsync(user);

            user.Roles = roles.ToList();

            model.User    = user;
            model.Profile = profile;

            return(View(model));
        }
예제 #5
0
        protected void SetProfileOnSession(Guid userId, string userName)
        {
            string sessionUserName = GetSessionValue(SessionValues.Username);

            if (sessionUserName != null && !sessionUserName.Equals(userName))
            {
                SetSessionValue(SessionValues.Username, userName);
            }

            string sessionFullName = GetSessionValue(SessionValues.FullName);

            if (sessionFullName == null)
            {
                ProfileViewModel profile = ProfileAppService.GetByUserId(userId, ProfileType.Personal);
                if (profile != null)
                {
                    SetSessionValue(SessionValues.FullName, profile.Name);
                }
            }
        }