Ejemplo n.º 1
0
        void ShowResult(Academic.DbEntities.ActivityAndResource.ChoiceActivity choice)
        {
            var lst        = new List <Academic.ViewModel.ChoiceResultViewModel>();
            var totalCount = choice.ChoiceUsers.Count;

            foreach (var c in choice.ChoiceOptions)
            {
                var usersCount = c.ChoiceUsers.Count;
                var percent    = (0.00);
                if (totalCount != 0)
                {
                    percent = (((1.0 * usersCount) / totalCount * 100));
                }
                lst.Add(new ChoiceResultViewModel()
                {
                    Id = c.Id
                    ,
                    ChoiceOption = c.Option
                    ,
                    NumberOfResponses = usersCount
                    ,
                    PercentageOfResponses = percent.ToString("N")
                });
            }
            ChoiceResponseView1.Visible = true;
            ChoiceResponseView1.SetData(lst);
        }
Ejemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                var list = new List <Academic.DbEntities.ActivityAndResource.ChoiceItems.ChoiceOptions>();

                var limitResponses = ddlLimitTheNumberOfResponses.SelectedIndex == 1;
                var choiceId       = ChoiceId;

                var choice = new Academic.DbEntities.ActivityAndResource.ChoiceActivity()
                {
                    Id   = choiceId,
                    Name = txtName.Text
                    ,
                    Description = txtDescription.Text
                    ,
                    DisplayDescriptionOnCoursePage = chkDisplayDescription.Checked
                    ,
                    DisplayModeForOptions = ddlDisplayModeForOptions.SelectedIndex == 1
                    ,
                    AllowChoiceTobeUpdated = ddlAllowChoiceToBeUpdated.SelectedIndex == 1
                    ,
                    AllowMoreThanOneChoiceToBeSelected = ddlAllowMoreChoiceToBeSelected.SelectedIndex == 1
                    ,
                    LimitTheNumberOfResponsesAllowed = limitResponses
                    ,
                    RestrictTimePeriod = chkRestrictAnsweringTime.Checked
                    ,
                    IncludeResponsesFromInactiveUsers = ddlIncludeResponsesFromInactiveUsers.SelectedIndex == 1
                    ,
                    PublishResults = (byte)ddlPublishResults.SelectedIndex
                    ,
                    //PrivacyOfResults = ddlPrivacyOfResults.SelectedIndex == 1
                    //,
                    ShowColumnForUnAnswered = ddlShowColumnsForUnanswered.SelectedIndex == 1
                    ,
                    ShowPreview = chkShowPreview.Checked
                    ,
                };
                if (chkRestrictAnsweringTime.Checked)
                {
                    choice.OpenDate  = Convert.ToDateTime(txtOpenDate.Text);
                    choice.UntilDate = Convert.ToDateTime(txtUntilDate.Text);
                }
                else
                {
                    choice.OpenDate  = null;
                    choice.UntilDate = null;
                }

                if (ddlPublishResults.SelectedIndex == 0)
                {
                    choice.PrivacyOfResults = false;
                }
                else
                {
                    choice.PrivacyOfResults = ddlPrivacyOfResults.SelectedIndex == 1;
                }


                //choice options
                foreach (var c in pnlOptions.Controls)
                {
                    var uc = c as ChoiceOptionsCreate;
                    if (uc != null)
                    {
                        if (uc.Visible)
                        {
                            list.Add(new ChoiceOptions()
                            {
                                Id = uc.OptionId
                                ,
                                Position = uc.Position
                                ,
                                Limit = (limitResponses) ? uc.LimitValue : 0
                                ,
                                Option = uc.OptionValue
                                ,
                                ChoiceActivityId = choiceId
                            });
                        }
                    }
                }

                var restriction = new Academic.DbEntities.AccessPermission.Restriction()
                {
                };

                using (var helper = new Academic.DbHelper.DbHelper.ActAndRes())
                {
                    var saved = helper.AddOrUpdateChoiceActivity(choice, list, SectionId, restriction);
                    if (saved != null)
                    {
                        Response.Redirect("~/Views/ActivityResource/Choice/ChoiceView.aspx" + "?SubId="
                                          + SubjectId + "&arId=" + saved.Id + "&secId=" + SectionId);//+ "&edit=" + (edit ? 1 : 0););
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void SetPrivacyOfResults(
            Academic.DbEntities.ActivityAndResource.ChoiceActivity choice, int userId, bool userAlreadySelected)
        {
            string message = "";

            //var selected = choice.ChoiceUsers.Where(x => x.UserId == userId).ToList();
            //var any = false;
            //try
            //{
            //    any = selected.Any();

            //}
            //catch { }

            switch (choice.PublishResults)
            {
            case 0:
                if (userAlreadySelected)
                {
                    message         = "The results are not currently available";
                    lblMessage.Text = message;
                }
                ChoiceResponseView1.Visible = false;
                break;

            case 1:
                if (userAlreadySelected)
                {
                    ShowResult(choice);
                }
                else
                {
                    ChoiceResponseView1.Visible = false;
                    //message = "The results are not currently available";
                    //lblMessage.Text = message;
                }
                break;

            case 2:
                if ((choice.UntilDate ?? DateTime.MaxValue) < DateTime.Now)
                {
                    //show result
                    ShowResult(choice);
                }
                else
                {
                    ChoiceResponseView1.Visible = false;
                    if (userAlreadySelected)
                    {
                        message         = "The results are not currently available";
                        lblMessage.Text = message;
                    }
                }
                break;

            case 3:
                //always show
                ShowResult(choice);
                break;
            }
        }