Example #1
0
        List <IdAndName> GetChoice(DbHelper.ActAndRes helper, string fileName)
        {
            var list = new List <IdAndName>();

            switch (fileName)
            {
            case "ChoiceCreate.aspx":
                list.Add(new IdAndName()
                {
                    Name = "Choice edit"
                });
                break;

            case "ChoiceView.aspx":
                var choiceId = Request.QueryString["arId"];
                var choice   = helper.GetChoiceActivity(Convert.ToInt32(choiceId));
                if (choice != null)
                {
                    list.Add(new IdAndName()
                    {
                        Name = choice.Name,
                    });
                }
                break;
            }
            return(list);
        }
Example #2
0
        void PopulateOptions()
        {
            var user = Page.User as CustomPrincipal;

            if (user != null)
            {
                using (var helper = new DbHelper.ActAndRes())
                    using (var shelper = new DbHelper.Subject())
                    {
                        //need to work out
                        //var enrolled = shelper.IsUserEnrolledToCourse(user.Id,SubjectId);

                        var choice = helper.GetChoiceActivity(ChoiceId);
                        ChoiceResponseView1.Visible = false;

                        if (choice != null)
                        {
                            var message = "";
                            //bool? showPreview = null;
                            var enabled             = true;
                            var visible             = true;
                            var choiceUsers         = choice.ChoiceUsers.Where(x => x.UserId == user.Id).ToList();
                            var userAlreadySelected = choiceUsers.Any();

                            lblTitle.Text       = choice.Name;
                            lblDescription.Text = choice.Description;

                            if (!userAlreadySelected)
                            {
                                if (choice.RestrictTimePeriod)
                                {
                                    //can't be choosen till open date or after until date
                                    var date = DateTime.Now.Date;
                                    if (date < choice.OpenDate)
                                    {
                                        message         = "The response time has not started yet.<br/>";
                                        btnSave.Visible = false;
                                        enabled         = false;
                                        //showPreview = choice.ShowPreview;
                                        visible = choice.ShowPreview;
                                    }
                                    else if (date > choice.UntilDate)
                                    {
                                        message         = "The response time has finished.<br/>";
                                        btnSave.Visible = false;
                                        enabled         = false;
                                        visible         = false;
                                        //showPreview = choice.ShowPreview;
                                    }
                                }
                            }
                            else if (!choice.AllowChoiceTobeUpdated)
                            {
                                enabled         = false;
                                btnSave.Visible = false;
                            }

                            //can be choosen -- if showPreview is true then the timelimit has crossed
                            // but still we have to show the choices, bt they shouldn't be selectable
                            //showpreview == null means that no date restriction is true

                            //user le select garisakyo ra update garna nadine , ho bhane dispaly garnu hudaina

                            #region show options for selections


                            if (visible)
                            {
                                if (choice.AllowMoreThanOneChoiceToBeSelected)
                                {
                                    foreach (var c in choice.ChoiceOptions)
                                    {
                                        var optionEnabled = enabled;
                                        var tooltip       = false;
                                        if (choice.LimitTheNumberOfResponsesAllowed)
                                        {
                                            if (c.Limit <= c.ChoiceUsers.Count)
                                            {
                                                optionEnabled = false;
                                                tooltip       = true;
                                            }
                                        }

                                        var choosen = c.ChoiceUsers.FirstOrDefault(x => x.UserId == user.Id &&
                                                                                   x.ChoiceOptionsId == c.Id);
                                        pnlOptions.Controls.Add(new CheckBox()
                                        {
                                            Text = c.Option
                                                   //chk_optonId_choiceUserId
                                            ,
                                            ID = "chk_" + c.Id + "_" + ((choosen == null) ? 0 : choosen.Id)
                                            ,
                                            Checked = choosen != null
                                            ,
                                            Enabled = optionEnabled
                                            ,
                                            ToolTip = tooltip ? "Limit exceed. If you want to select this, then you better not answer." : ""
                                        });
                                        pnlOptions.Controls.Add(new Literal()
                                        {
                                            Text = (choice.DisplayModeForOptions) ? "<br />" : "&nbsp;"
                                        });
                                    }
                                }
                                else
                                {
                                    foreach (var c in choice.ChoiceOptions)
                                    {
                                        var optionEnabled = enabled;
                                        var tooltip       = false;
                                        if (choice.LimitTheNumberOfResponsesAllowed)
                                        {
                                            if (c.Limit >= c.ChoiceUsers.Count)
                                            {
                                                optionEnabled = false;
                                                tooltip       = true;
                                            }
                                        }

                                        var choosen = c.ChoiceUsers.FirstOrDefault(x => x.UserId == user.Id);
                                        pnlOptions.Controls.Add(new RadioButton()
                                        {
                                            Text = c.Option
                                                   //chk_optonId_choiceUserId
                                            ,
                                            ID = "chk_" + c.Id + "_" + ((choosen == null) ? 0 : choosen.Id)
                                            ,
                                            Checked = choosen != null
                                            ,
                                            GroupName = "choice"
                                            ,
                                            Enabled = optionEnabled
                                            ,
                                            ToolTip = tooltip ? "Limit exceed. If you want to select this, then you better not answer." : ""
                                        });
                                        pnlOptions.Controls.Add(new Literal()
                                        {
                                            Text = (choice.DisplayModeForOptions) ? "<br />" : "&nbsp;"
                                        });
                                    }
                                }
                            }


                            #endregion


                            pnlOptions.Controls.Add(new Literal()
                            {
                                Text = "<br/><div style='text-align:center; color:red; font-weight:600;'>"
                                       +
                                       message
                                       + "</div>"
                            });

                            SetPrivacyOfResults(choice, user.Id, userAlreadySelected);
                        }
                    }
            }
        }