Ejemplo n.º 1
0
        public async Task <IActionResult> CompleteTasks(ChallengeDetailViewModel model)
        {
            List <ChallengeTask> tasks = _mapper.Map <List <ChallengeTask> >(model.Tasks);

            try
            {
                var completed = await _activityService.UpdateChallengeTasksAsync(model.Challenge.Id, tasks);

                if (!completed)
                {
                    var challenge
                        = await _challengeService.GetChallengeDetailsAsync(model.Challenge.Id);

                    if (challenge.TasksToComplete != null &&
                        challenge.TasksToComplete > 0)
                    {
                        int tasksCompleted = model.Tasks.Where(_ => _.IsCompleted == true).Count();
                        int percentage     = tasksCompleted * 100 / (int)challenge.TasksToComplete;
                        ShowAlertSuccess($"Your status has been saved. You have completed {percentage}% of the required tasks for the challenge: {challenge.Name}!");
                    }
                    else
                    {
                        ShowAlertSuccess("Your status has been saved!");
                    }
                }
            }
            catch (GraException gex)
            {
                AlertInfo = gex.Message;
            }
            return(RedirectToAction("Detail", new { id = model.Challenge.Id }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CompleteTasks(ChallengeDetailViewModel model)
        {
            List <ChallengeTask> tasks = _mapper.Map <List <ChallengeTask> >(model.Tasks);

            try
            {
                var completed = await _activityService
                                .UpdateChallengeTasksAsync(model.Challenge.Id, tasks);

                if (!completed)
                {
                    var challenge
                        = await _challengeService.GetChallengeDetailsAsync(model.Challenge.Id);

                    if (challenge.TasksToComplete != null &&
                        challenge.TasksToComplete > 0)
                    {
                        int tasksCompleted = model.Tasks.Count(_ => _.IsCompleted);
                        int percentage     = tasksCompleted * 100 / (int)challenge.TasksToComplete;
                        ShowAlertSuccess(_sharedLocalizer[Annotations.Info.StatusSavedPercentage,
                                                          percentage,
                                                          challenge.Name]);
                    }
                    else
                    {
                        ShowAlertSuccess(_sharedLocalizer[Annotations.Info.StatusSaved]);
                    }
                }
            }
            catch (GraException gex)
            {
                AlertInfo = gex.Message;
            }
            return(RedirectToAction(nameof(Detail), new { id = model.Challenge.Id }));
        }
Ejemplo n.º 3
0
        public ActionResult ShowRequestChallengeDetail(int id)
        {
            var       result            = new AjaxOperationResult <ChallengeDetailViewModel>();
            var       _challengeService = this.Service <IChallengeService>();
            Challenge cha = _challengeService.FindById(id);

            if (cha != null)
            {
                ChallengeDetailViewModel model = Mapper.Map <ChallengeDetailViewModel>(cha);
                result.AdditionalData = model;
                result.Succeed        = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Detail(int id)
        {
            Challenge challenge = new Domain.Model.Challenge();

            try
            {
                challenge = await _challengeService.GetChallengeDetailsAsync(id);
            }
            catch (GraException gex)
            {
                ShowAlertWarning("Unable to view challenge: ", gex);
                return(RedirectToAction("Index"));
            }
            var siteStage = GetSiteStage();

            if (!string.IsNullOrEmpty(challenge.BadgeFilename))
            {
                challenge.BadgeFilename = _pathResolver.ResolveContentPath(challenge.BadgeFilename);
            }

            bool isActive      = AuthUser.Identity.IsAuthenticated && siteStage == SiteStage.ProgramOpen;
            bool showCompleted = siteStage == SiteStage.ProgramOpen ||
                                 siteStage == SiteStage.ProgramEnded;

            ChallengeDetailViewModel viewModel = new ChallengeDetailViewModel()
            {
                Challenge     = challenge,
                BadgePath     = challenge.BadgeFilename,
                IsActive      = isActive,
                ShowCompleted = showCompleted,
                Tasks         = new List <TaskDetailViewModel>()
            };

            viewModel.Details = $"Completing <strong>{challenge.TasksToComplete} "
                                + $"{(challenge.TasksToComplete > 1 ? "Tasks" : "Task")}</strong> will earn: "
                                + $"<strong>{challenge.PointsAwarded} "
                                + $"{(challenge.PointsAwarded > 1 ? "Points" : "Point")}</strong> and "
                                + "<strong>a badge</strong>.";

            foreach (var task in challenge.Tasks)
            {
                TaskDetailViewModel taskModel = new TaskDetailViewModel()
                {
                    Id          = task.Id,
                    IsCompleted = task.IsCompleted ?? false,
                    TaskType    = task.ChallengeTaskType.ToString(),
                    Url         = task.Url
                };
                if (task.ChallengeTaskType.ToString() == "Book")
                {
                    string description = $"Read <strong><em>{task.Title}</em></strong>";
                    if (!string.IsNullOrWhiteSpace(task.Author))
                    {
                        description += $" by <strong>{task.Author}</strong>";
                    }
                    taskModel.Description = description;
                }
                else
                {
                    taskModel.Description = task.Title;
                }
                viewModel.Tasks.Add(taskModel);
            }
            return(View(viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult UpdateChallenge(int challengeId, int status)
        {
            var _challengeService = this.Service <IChallengeService>();
            var result            = new AjaxOperationResult();

            if (_challengeService.UpdateChallenge(challengeId, status) == true)
            {
                Challenge cha = _challengeService.FindById(challengeId);
                ChallengeDetailViewModel chaVM = Mapper.Map <ChallengeDetailViewModel>(cha);
                string curUser = User.Identity.GetUserId();
                //save noti
                var    _notificationService = this.Service <INotificationService>();
                var    _groupMemberService  = this.Service <IGroupMemberService>();
                string title   = "";
                int    type    = -1;
                string message = "";

                switch (status)
                {
                case (int)ChallengeStatus.NotOperate:
                    GroupMember gm = _groupMemberService.FirstOrDefaultActive(g => g.GroupId == cha.Group.Id && g.Admin == true && g.Status == (int)GroupMemberStatus.Approved);
                    //save noti
                    title   = Utils.GetEnumDescription(NotificationType.GroupChallengeInvitation);
                    type    = (int)NotificationType.GroupChallengeInvitation;
                    message = "Nhóm " + chaVM.Group1.Name + " đã đồng ý lời thách đấu từ nhóm " + cha.Group.Name + " của bạn";
                    Notification noti = _notificationService.CreateNoti(gm.UserId, curUser, title, message, type, null, null, null, cha.Group1.Id);

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModel.UserId).send(notiModel);
                    break;

                case (int)ChallengeStatus.NotAvailable:
                    GroupMember gm1 = _groupMemberService.FirstOrDefaultActive(g => g.GroupId == cha.Group.Id && g.Admin == true && g.Status == (int)GroupMemberStatus.Approved);
                    //save noti
                    title   = Utils.GetEnumDescription(NotificationType.GroupChallengeInvitation);
                    type    = (int)NotificationType.GroupChallengeInvitation;
                    message = "Nhóm " + chaVM.Group1.Name + " đã từ chối lời thách đấu từ nhóm " + cha.Group.Name + " của bạn";
                    Notification noti1 = _notificationService.CreateNoti(gm1.UserId, curUser, title, message, type, null, null, null, cha.Group1.Id);

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel1 = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti1));

                    // Get the context for the Pusher hub
                    IHubContext hubContext1 = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext1.Clients.User(notiModel1.UserId).send(notiModel1);
                    break;
                }
                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Detail(int id)
        {
            Challenge challenge;

            try
            {
                challenge = await _challengeService.GetChallengeDetailsAsync(id);
            }
            catch (GraException gex)
            {
                ShowAlertWarning(gex.Message);
                return(await Index(httpStatus : System.Net.HttpStatusCode.NotFound));
            }
            var siteStage = GetSiteStage();

            if (!string.IsNullOrEmpty(challenge.BadgeFilename))
            {
                challenge.BadgeFilename = _pathResolver.ResolveContentPath(challenge.BadgeFilename);
            }

            bool isActive      = AuthUser.Identity.IsAuthenticated && siteStage == SiteStage.ProgramOpen;
            bool showCompleted = siteStage == SiteStage.ProgramOpen ||
                                 siteStage == SiteStage.ProgramEnded;

            var viewModel = new ChallengeDetailViewModel
            {
                Challenge                = challenge,
                BadgePath                = challenge.BadgeFilename,
                BadgeAltText             = challenge.BadgeAltText,
                IsActive                 = isActive,
                IsLoggedIn               = AuthUser.Identity.IsAuthenticated,
                ShowCompleted            = showCompleted,
                Tasks                    = new List <TaskDetailViewModel>(),
                IsBadgeEarning           = challenge.BadgeId.HasValue,
                PointCountAndDescription = challenge.PointsAwarded == 1
                    ? _sharedLocalizer[Annotations.Info.PointSingular, challenge.PointsAwarded]
                    : _sharedLocalizer[Annotations.Info.PointsPlural, challenge.PointsAwarded],
                TaskCountAndDescription = challenge.TasksToComplete == 1
                    ? _sharedLocalizer[Annotations.Info.TaskSingular, challenge.TasksToComplete]
                    : _sharedLocalizer[Annotations.Info.TasksPlural, challenge.TasksToComplete]
            };

            var siteUrl = await _siteLookupService.GetSiteLinkAsync(GetCurrentSiteId());

            foreach (var task in challenge.Tasks)
            {
                var taskModel = new TaskDetailViewModel
                {
                    Id          = task.Id,
                    IsCompleted = task.IsCompleted ?? false,
                    TaskType    = task.ChallengeTaskType.ToString(),
                    Url         = task.Url,
                    Title       = task.Title,
                    Author      = task.Author
                };
                if (taskModel.TaskType != "Book")
                {
                    taskModel.Description = CommonMark.CommonMarkConverter.Convert(task.Title);
                }
                if (!string.IsNullOrWhiteSpace(task.Filename))
                {
                    var contentPath = _pathResolver.ResolveContentPath(task.Filename);
                    taskModel.FilePath = $"{siteUrl}{contentPath}";
                }
                viewModel.Tasks.Add(taskModel);
            }
            PageTitle = _sharedLocalizer[Annotations.Title.ChallengeDetails, challenge.Name];
            return(View(viewModel));
        }