示例#1
0
        private async Task OnJoinExam()
        {
            var(res, details) = await ExamServices.GetExamDetails(_examIdToJoin);

            if (res != ErrorCodes.Success)
            {
                await Modal.ErrorAsync(new ConfirmOptions()
                {
                    Title   = "Cannot obtain exam information",
                    Content = ErrorCodes.MessageMap[res]
                });

                return;
            }

            var confirm = await Modal.ConfirmAsync(new ConfirmOptions()
            {
                Title   = "Confirm to join exam",
                Content = RenderExamDescription(details)
            });

            if (confirm)
            {
                var(re, banReason) = await ExamServices.JoinExam(_examIdToJoin);

                if (re != ErrorCodes.Success)
                {
                    await Modal.ErrorAsync(new ConfirmOptions()
                    {
                        Title   = "Cannot join the exam",
                        Content = ErrorCodes.MessageMap[re] + (banReason == null ? "" : " Reason: " + banReason)
                    });

                    return;
                }

                await Modal.SuccessAsync(new ConfirmOptions()
                {
                    Content = "You have successfully joined the exam."
                });
            }

            _joinExamModalVisible = false;
        }