Exemplo n.º 1
0
        /// <summary>
        /// Handles the GridReorder event of the gList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void gList_GridReorder(object sender, GridReorderEventArgs e)
        {
            int oldIndex  = e.OldIndex;
            int newIndex  = e.NewIndex;
            int projectId = hfProjectId.ValueAsInt();

            var projectPointOfAssessmentService = new ResidencyService <ProjectPointOfAssessment>();
            var items = projectPointOfAssessmentService.Queryable()
                        .Where(a => a.ProjectId.Equals(projectId))
                        .OrderBy(a => a.AssessmentOrder).ToList();

            ProjectPointOfAssessment movedItem = items[oldIndex];

            items.RemoveAt(oldIndex);
            if (newIndex >= items.Count)
            {
                items.Add(movedItem);
            }
            else
            {
                items.Insert(newIndex, movedItem);
            }

            UpdateItemOrders(projectPointOfAssessmentService, items);

            BindGrid();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the Delete event of the gList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gList_Delete(object sender, RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                var projectPointOfAssessmentService = new ResidencyService <ProjectPointOfAssessment>();

                ProjectPointOfAssessment projectPointOfAssessment = projectPointOfAssessmentService.Get((int)e.RowKeyValue);
                if (projectPointOfAssessment != null)
                {
                    string errorMessage;
                    if (!projectPointOfAssessmentService.CanDelete(projectPointOfAssessment, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    projectPointOfAssessmentService.Delete(projectPointOfAssessment, CurrentPersonId);
                    projectPointOfAssessmentService.Save(projectPointOfAssessment, CurrentPersonId);

                    int iProjectId = hfProjectId.ValueAsInt();

                    // after an item is deleted, we need to renumber all the items
                    List <ProjectPointOfAssessment> items = projectPointOfAssessmentService.Queryable().Where(a => a.ProjectId == iProjectId).OrderBy(a => a.AssessmentOrder).ToList();
                    UpdateItemOrders(projectPointOfAssessmentService, items);
                }
            });

            BindGrid();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determines whether this instance can delete the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns>
        ///   <c>true</c> if this instance can delete the specified item; otherwise, <c>false</c>.
        /// </returns>
        public bool CanDelete(ProjectPointOfAssessment item, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (new ResidencyService <CompetencyPersonProjectAssessmentPointOfAssessment>().Queryable().Any(a => a.ProjectPointOfAssessmentId == item.Id))
            {
                errorMessage = string.Format("This {0} is assigned to a {1}.", ProjectPointOfAssessment.FriendlyTypeName, CompetencyPersonProjectAssessmentPointOfAssessment.FriendlyTypeName);
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            ProjectPointOfAssessment projectPointOfAssessment;
            ResidencyService <ProjectPointOfAssessment> projectPointOfAssessmentService = new ResidencyService <ProjectPointOfAssessment>();

            int projectPointOfAssessmentId = int.Parse(hfProjectPointOfAssessmentId.Value);

            if (projectPointOfAssessmentId == 0)
            {
                projectPointOfAssessment = new ProjectPointOfAssessment();
                projectPointOfAssessment.AssessmentOrder = lblAssessmentOrder.Text.AsInteger().Value;
                projectPointOfAssessment.ProjectId       = hfProjectId.ValueAsInt();
                projectPointOfAssessmentService.Add(projectPointOfAssessment, CurrentPersonId);
            }
            else
            {
                projectPointOfAssessment = projectPointOfAssessmentService.Get(projectPointOfAssessmentId);
            }

            projectPointOfAssessment.PointOfAssessmentTypeValueId = ddlPointOfAssessmentTypeValue.SelectedValueAsInt();
            projectPointOfAssessment.AssessmentText = tbAssessmentText.Text;

            if (!projectPointOfAssessment.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                projectPointOfAssessmentService.Save(projectPointOfAssessment, CurrentPersonId);
            });

            Dictionary <string, string> qryString = new Dictionary <string, string>();

            qryString["projectId"] = hfProjectId.Value;
            NavigateToParentPage(qryString);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shows the detail
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        /// <param name="projectId">The residency project id.</param>
        public void ShowDetail(string itemKey, int itemKeyValue, int?projectId)
        {
            // return if unexpected itemKey
            if (itemKey != "projectPointOfAssessmentId")
            {
                return;
            }

            pnlDetails.Visible = true;

            LoadDropDowns();

            // Load depending on Add(0) or Edit
            ProjectPointOfAssessment projectPointOfAssessment = null;
            var projectPointOfAssessmentService = new ResidencyService <ProjectPointOfAssessment>();

            string projectName = new ResidencyService <Project>().Queryable()
                                 .Where(a => a.Id.Equals(projectId.Value))
                                 .Select(a => a.Name).FirstOrDefault();

            if (!itemKeyValue.Equals(0))
            {
                projectPointOfAssessment = projectPointOfAssessmentService.Get(itemKeyValue);
                lActionTitle.Text        = ActionTitle.Edit("Point of Assessment " + projectPointOfAssessment.AssessmentOrder.ToString());
            }
            else
            {
                // don't try add if there wasn't a projectId specified
                if (projectId != null)
                {
                    projectPointOfAssessment = new ProjectPointOfAssessment {
                        Id = 0, ProjectId = projectId.Value
                    };

                    int maxAssessmentOrder = projectPointOfAssessmentService.Queryable()
                                             .Where(a => a.ProjectId.Equals(projectPointOfAssessment.ProjectId))
                                             .Select(a => a.AssessmentOrder).DefaultIfEmpty(0).Max();

                    projectPointOfAssessment.AssessmentOrder = maxAssessmentOrder + 1;

                    lActionTitle.Text = ActionTitle.Add("Point of Assessment " + projectPointOfAssessment.AssessmentOrder.ToString());
                }
            }

            if (projectPointOfAssessment == null)
            {
                return;
            }

            hfProjectPointOfAssessmentId.Value = projectPointOfAssessment.Id.ToString();
            hfProjectId.Value       = projectId.ToString();
            lblAssessmentOrder.Text = projectPointOfAssessment.AssessmentOrder.ToString();
            tbAssessmentText.Text   = projectPointOfAssessment.AssessmentText;
            ddlPointOfAssessmentTypeValue.SetValue(projectPointOfAssessment.PointOfAssessmentTypeValueId);

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed("Point of Assessment");
            }

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View("Point of Assessment " + projectPointOfAssessment.AssessmentOrder.ToString());
                btnCancel.Text    = "Close";
            }

            tbAssessmentText.ReadOnly = readOnly;
            btnSave.Visible           = !readOnly;
        }