コード例 #1
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();
        }
コード例 #2
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var projectPointOfAssessmentService = new ResidencyService <ProjectPointOfAssessment>();
            int projectId = hfProjectId.ValueAsInt();
            var rawList   = projectPointOfAssessmentService.Queryable()
                            .Where(a => a.ProjectId == projectId)
                            .OrderBy(s => s.AssessmentOrder).ToList();

            foreach (var item in rawList)
            {
                if (item.PointOfAssessmentTypeValue != null)
                {
                    item.PointOfAssessmentTypeValue.LoadAttributes();
                }
            }

            var selectList = rawList.Select(a =>
                                            new
            {
                a.Id,
                ProjectPointOfAssessmentColor = a.PointOfAssessmentTypeValue != null ? a.PointOfAssessmentTypeValue.GetAttributeValue("Color") : string.Empty,
                a.PointOfAssessmentTypeValue,
                a.AssessmentOrder,
                a.AssessmentText,
            }).ToList();

            gList.DataSource = selectList;
            gList.DataBind();
        }
コード例 #3
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var          competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>();
            int          competencyPersonId             = hfCompetencyPersonId.ValueAsInt();
            SortProperty sortProperty = gList.SortProperty;
            var          qry          = competencyPersonProjectService.Queryable();

            qry = qry.Where(a => a.CompetencyPersonId.Equals(competencyPersonId));

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderBy(s => s.Project.Name).ThenBy(s => s.Project.Description);
            }

            var list = qry.Select(a => new
            {
                Id                 = a.Id,
                Name               = a.Project.Name,
                Description        = a.Project.Description,
                MinAssessmentCount = a.MinAssessmentCount ?? a.Project.MinAssessmentCountDefault,
                CurrentCompleted   = a.CompetencyPersonProjectAssessments.Where(b => b.AssessmentDateTime != null).Count()
            }).ToList();

            gList.DataSource = list;
            gList.DataBind();
        }
コード例 #4
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var          competencyPersonService = new ResidencyService <CompetencyPerson>();
            int          personId     = hfPersonId.ValueAsInt();
            SortProperty sortProperty = gList.SortProperty;
            var          qry          = competencyPersonService.Queryable()
                                        .Where(a => a.PersonId.Equals(personId))
                                        .Select(a => new
            {
                Id = a.Id,
                TrackDisplayOrder = a.Competency.Track.DisplayOrder,
                TrackName         = a.Competency.Track.Name,
                CompetencyName    = a.Competency.Name,
                CompletedProjectAssessmentsTotal = a.CompetencyPersonProjects.Select(p => p.CompetencyPersonProjectAssessments).SelectMany(x => x).Where(n => n.AssessmentDateTime != null).Count(),
                MinAssessmentCount = a.CompetencyPersonProjects.Select(p => p.MinAssessmentCount ?? p.Project.MinAssessmentCountDefault).Sum()
            });

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderBy(s => s.TrackDisplayOrder).ThenBy(s => s.TrackName).ThenBy(s => s.CompetencyName);
            }

            gList.DataSource = qry.ToList();
            gList.DataBind();
        }
コード例 #5
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var          competencyPersonProjectAssessmentService = new ResidencyService <CompetencyPersonProjectAssessment>();
            int          competencyPersonProjectId = hfCompetencyPersonProjectId.ValueAsInt();
            SortProperty sortProperty = gList.SortProperty;

            var qry = competencyPersonProjectAssessmentService.Queryable("AssessorPerson");

            if (competencyPersonProjectId != 0)
            {
                // limit to specific project (and current person)
                qry = qry.Where(a => a.CompetencyPersonProjectId.Equals(competencyPersonProjectId));
            }
            else
            {
                // limit only to current person
                qry = qry.Where(a => a.CompetencyPersonProject.CompetencyPerson.PersonId == this.CurrentPersonId);
            }


            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderByDescending(s => s.AssessmentDateTime).ThenBy(s => s.AssessorPerson);
            }

            gList.DataSource = qry.ToList();
            gList.DataBind();
        }
コード例 #6
0
        /// <summary>
        /// Handles the ItemDataBound event of the rpTracks control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param>
        protected void rpTracks_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            Track track = e.Item.DataItem as Track;

            if (track != null)
            {
                int  trackId                 = track.Id;
                int  currentPersonId         = this.CurrentPersonId ?? 0;
                Grid gCompetencyList         = e.Item.FindControl("gCompetencyList") as Grid;
                var  competencyPersonService = new ResidencyService <CompetencyPerson>();

                var qryPersonCompetencies = competencyPersonService.Queryable()
                                            .Where(a => a.PersonId.Equals(currentPersonId) && a.Competency.TrackId.Equals(trackId))
                                            .Select(a => new
                {
                    Id             = a.Id,
                    CompetencyName = a.Competency.Name,
                    CompletedProjectAssessmentsTotal = a.CompetencyPersonProjects.Select(p => p.CompetencyPersonProjectAssessments).SelectMany(x => x).Where(n => n.AssessmentDateTime != null).Count(),
                    MinProjectAssessmentsTotal       = a.CompetencyPersonProjects.Select(p => p.MinAssessmentCount ?? p.Project.MinAssessmentCountDefault ?? 0).DefaultIfEmpty().Sum()
                })
                                            .OrderBy(o => o.CompetencyName);

                gCompetencyList.DataKeyNames    = new string[] { "Id" };
                gCompetencyList.DisplayType     = GridDisplayType.Light;
                gCompetencyList.Actions.ShowAdd = false;
                gCompetencyList.RowSelected    += gCompetencyList_RowSelected;
                gCompetencyList.GridRebind     += gCompetencyList_GridRebind;
                gCompetencyList.DataSource      = qryPersonCompetencies.ToList();
                gCompetencyList.DataBind();
            }
        }
コード例 #7
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var competencyService = new ResidencyService <Competency>();
            int trackId           = hfTrackId.ValueAsInt();

            SortProperty            sortProperty = gList.SortProperty;
            IQueryable <Competency> qry          = competencyService.Queryable();

            qry = qry.Where(a => a.TrackId.Equals(trackId));

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry
                      .OrderBy(s => s.Track.Period.Name)
                      .ThenBy(s => s.Track.Name)
                      .ThenBy(s => s.Name);
            }

            gList.DataSource = qry.ToList();

            gList.DataBind();
        }
コード例 #8
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();
        }
コード例 #9
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var          periodService = new ResidencyService <Period>();
            SortProperty sortProperty  = gList.SortProperty;

            if (sortProperty != null)
            {
                gList.DataSource = periodService.Queryable().Sort(sortProperty).ToList();
            }
            else
            {
                gList.DataSource = periodService.Queryable().OrderBy(s => s.Name).ToList();
            }

            gList.DataBind();
        }
コード例 #10
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)
        {
            int projectPointOfAssessmentId          = hfProjectPointOfAssessmentId.ValueAsInt();
            int competencyPersonProjectAssessmentId = hfCompetencyPersonProjectAssessmentId.ValueAsInt();

            var competencyPersonProjectAssessmentPointOfAssessmentService = new ResidencyService <CompetencyPersonProjectAssessmentPointOfAssessment>();
            CompetencyPersonProjectAssessmentPointOfAssessment competencyPersonProjectAssessmentPointOfAssessment = null;

            competencyPersonProjectAssessmentPointOfAssessment = competencyPersonProjectAssessmentPointOfAssessmentService.Queryable()
                                                                 .Where(a => a.ProjectPointOfAssessmentId.Equals(projectPointOfAssessmentId) && a.CompetencyPersonProjectAssessmentId.Equals(competencyPersonProjectAssessmentId))
                                                                 .FirstOrDefault();

            if (competencyPersonProjectAssessmentPointOfAssessment == null)
            {
                // Create a record to store the rating for this PointOfAssessment if one doesn't already exist
                competencyPersonProjectAssessmentPointOfAssessment = new CompetencyPersonProjectAssessmentPointOfAssessment {
                    Id = 0
                };
                competencyPersonProjectAssessmentPointOfAssessment.ProjectPointOfAssessmentId          = projectPointOfAssessmentId;
                competencyPersonProjectAssessmentPointOfAssessment.CompetencyPersonProjectAssessmentId = competencyPersonProjectAssessmentId;
                competencyPersonProjectAssessmentPointOfAssessmentService.Add(competencyPersonProjectAssessmentPointOfAssessment, CurrentPersonId);
            }

            competencyPersonProjectAssessmentPointOfAssessment.Rating      = tbRating.Text.AsInteger();
            competencyPersonProjectAssessmentPointOfAssessment.RatingNotes = tbRatingNotes.Text;

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

            RockTransactionScope.WrapTransaction(() =>
            {
                competencyPersonProjectAssessmentPointOfAssessmentService.Save(competencyPersonProjectAssessmentPointOfAssessment, CurrentPersonId);

                // get the CompetencyPersonProjectAssessment using the same dbContext
                var competencyPersonProjectAssessmentService = new ResidencyService <CompetencyPersonProjectAssessment>(competencyPersonProjectAssessmentPointOfAssessmentService.ResidencyContext);
                CompetencyPersonProjectAssessment competencyPersonProjectAssessment = competencyPersonProjectAssessmentService.Get(competencyPersonProjectAssessmentId);

                // set Overall Rating based on average of POA ratings
                competencyPersonProjectAssessment.OverallRating = (decimal?)competencyPersonProjectAssessment.CompetencyPersonProjectAssessmentPointOfAssessments.Average(a => a.Rating);
                competencyPersonProjectAssessmentService.Save(competencyPersonProjectAssessment, CurrentPersonId);
            });

            if (competencyPersonProjectAssessmentId != 0)
            {
                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["competencyPersonProjectAssessmentId"] = competencyPersonProjectAssessmentId.ToString();
                NavigateToParentPage(qryString);
            }
            else
            {
                NavigateToParentPage();
            }
        }
コード例 #11
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 periodId = hfPeriodId.ValueAsInt();

            var trackService = new ResidencyService <Track>();
            var items        = trackService.Queryable()
                               .Where(a => a.PeriodId.Equals(periodId))
                               .OrderBy(a => a.DisplayOrder).ToList();

            RockTransactionScope.WrapTransaction(() =>
            {
                Track movedItem = items[oldIndex];
                items.RemoveAt(oldIndex);
                if (newIndex >= items.Count)
                {
                    items.Add(movedItem);
                }
                else
                {
                    items.Insert(newIndex, movedItem);
                }

                int order = 1;
                foreach (Track item in items)
                {
                    if (item != null)
                    {
                        if (item.DisplayOrder != order)
                        {
                            // temporarily, set the order to negative in case another row has this value.
                            item.DisplayOrder = -order;
                            trackService.Save(item, CurrentPersonId);
                        }
                    }

                    order++;
                }

                foreach (Track item in items)
                {
                    if (item != null)
                    {
                        if (item.DisplayOrder < 0)
                        {
                            // update the value back to positive now that all the rows have their new order
                            item.DisplayOrder = -item.DisplayOrder;
                            trackService.Save(item, CurrentPersonId);
                        }
                    }
                }
            });

            BindGrid();
        }
コード例 #12
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var residencyGroupMemberService = new ResidencyService <Rock.Model.GroupMember>();

            int residencyGroupId = PageParameter("groupId").AsInteger() ?? 0;

            hfGroupId.SetValue(residencyGroupId);

            var residencyGroupMemberList = residencyGroupMemberService.Queryable()
                                           .Where(a => a.GroupId.Equals(residencyGroupId)).ToList();

            var competencyPersonService = new ResidencyService <CompetencyPerson>();
            List <IGrouping <int, CompetencyPerson> > competencyPersonQry = competencyPersonService.Queryable().GroupBy(a => a.PersonId).ToList();

            var groupMemberCompetencies = from groupMember in residencyGroupMemberList
                                          join competencyList in competencyPersonQry on groupMember.PersonId
                                          equals competencyList.Key into groupJoin
                                          from qryResult in groupJoin.DefaultIfEmpty()
                                          select new
            {
                GroupMember           = groupMember,
                ResidentCompentencies = qryResult != null?qryResult.ToList() : null
            };

            var dataResult = groupMemberCompetencies.Select(a => new
            {
                Id              = a.GroupMember.Id,
                FullName        = a.GroupMember.Person.FullName,
                CompetencyCount = a.ResidentCompentencies == null ? 0 : a.ResidentCompentencies.Count(),
                CompletedProjectAssessmentsTotal = a.ResidentCompentencies == null
                    ? 0
                    : a.ResidentCompentencies.SelectMany(cp => cp.CompetencyPersonProjects).SelectMany(x => x.CompetencyPersonProjectAssessments).Where(y => y.AssessmentDateTime != null).Count(),
                MinAssessmentCount = a.ResidentCompentencies == null
                    ? 0
                    : a.ResidentCompentencies.SelectMany(cp => cp.CompetencyPersonProjects).Select(x => x.MinAssessmentCount ?? x.Project.MinAssessmentCountDefault ?? 0).Sum(),
            });

            SortProperty sortProperty = gList.SortProperty;

            if (sortProperty != null)
            {
                gList.DataSource = dataResult.AsQueryable().Sort(sortProperty).ToList();
            }
            else
            {
                gList.DataSource = dataResult.OrderBy(s => s.FullName).ToList();
            }

            gList.DataBind();
        }
コード例 #13
0
        /// <summary>
        /// Binds the repeater.
        /// </summary>
        private void BindRepeater()
        {
            var trackService            = new ResidencyService <Track>();
            var competencyPersonService = new ResidencyService <CompetencyPerson>();
            int currentPersonId         = this.CurrentPersonId ?? 0;

            List <int> residentCompetencyIds = competencyPersonService.Queryable().Where(a => a.PersonId.Equals(currentPersonId))
                                               .Select(x => x.CompetencyId).Distinct().ToList();

            var qryPersonTracks = trackService.Queryable().Where(a => residentCompetencyIds.Any(rc => a.Competencies.Select(c => c.Id).Contains(rc)))
                                  .OrderBy(o => o.DisplayOrder);

            rpTracks.DataSource = qryPersonTracks.ToList();
            rpTracks.DataBind();
        }
コード例 #14
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)
        {
            Track track;
            ResidencyService <Track> trackService = new ResidencyService <Track>();

            int trackId  = hfTrackId.ValueAsInt();
            int periodId = hfPeriodId.ValueAsInt();

            if (trackId == 0)
            {
                track = new Track();
                trackService.Add(track, CurrentPersonId);

                int maxDisplayOrder = trackService.Queryable()
                                      .Where(a => a.PeriodId.Equals(periodId))
                                      .Select(a => a.DisplayOrder).DefaultIfEmpty(0).Max();
                track.DisplayOrder = maxDisplayOrder + 1;
            }
            else
            {
                track = trackService.Get(trackId);
            }

            track.Name        = tbName.Text;
            track.Description = tbDescription.Text;
            track.PeriodId    = periodId;

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

            RockTransactionScope.WrapTransaction(() =>
            {
                trackService.Save(track, CurrentPersonId);
            });

            var qryParams = new Dictionary <string, string>();

            qryParams["trackId"] = track.Id.ToString();
            NavigateToPage(this.CurrentPage.Guid, qryParams);
        }
コード例 #15
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 groupMemberService = new GroupMemberService();
                int groupMemberId      = (int)e.RowKeyValue;

                GroupMember groupMember = groupMemberService.Get(groupMemberId);
                if (groupMember != null)
                {
                    // check if person can be removed from the Group and also check if person can be removed from all the person assigned competencies
                    string errorMessage;
                    if (!groupMemberService.CanDelete(groupMember, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    var competencyPersonService = new ResidencyService <CompetencyPerson>();
                    var personCompetencyList    = competencyPersonService.Queryable().Where(a => a.PersonId.Equals(groupMember.PersonId));
                    foreach (var item in personCompetencyList)
                    {
                        if (!competencyPersonService.CanDelete(item, out errorMessage))
                        {
                            mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                            return;
                        }
                    }

                    // if you made it this far, delete all person's assigned competencies, and finally delete from Group
                    foreach (var item in personCompetencyList)
                    {
                        competencyPersonService.Delete(item, CurrentPersonId);
                        competencyPersonService.Save(item, CurrentPersonId);
                    }

                    groupMemberService.Delete(groupMember, CurrentPersonId);
                    groupMemberService.Save(groupMember, CurrentPersonId);
                }
            });

            BindGrid();
        }
コード例 #16
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var          trackService = new ResidencyService <Track>();
            int          periodId     = hfPeriodId.ValueAsInt();
            SortProperty sortProperty = gList.SortProperty;
            var          qry          = trackService.Queryable();

            qry = qry.Where(a => a.PeriodId.Equals(periodId));

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderBy(s => s.DisplayOrder).ThenBy(s => s.Name);
            }

            gList.DataSource = qry.ToList();
            gList.DataBind();
        }
コード例 #17
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var          competencyPersonProjectAssessmentService = new ResidencyService <CompetencyPersonProjectAssessment>();
            int          competencyPersonProjectId = hfCompetencyPersonProjectId.ValueAsInt();
            SortProperty sortProperty = gList.SortProperty;
            var          qry          = competencyPersonProjectAssessmentService.Queryable();

            qry = qry.Where(a => a.CompetencyPersonProjectId.Equals(competencyPersonProjectId));

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderByDescending(s => s.AssessmentDateTime);
            }

            gList.DataSource = qry.ToList();
            gList.DataBind();
        }
コード例 #18
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var          projectService = new ResidencyService <Project>();
            int          competencyId   = hfCompetencyId.ValueAsInt();
            SortProperty sortProperty   = gList.SortProperty;
            var          qry            = projectService.Queryable();

            qry = qry.Where(a => a.CompetencyId.Equals(competencyId));

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderBy(s => s.Name);
            }

            gList.DataSource = qry.ToList();

            gList.DataBind();
        }
コード例 #19
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)
        {
            CompetencyPersonProject competencyPersonProject;
            ResidencyService <CompetencyPersonProject> competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>();

            CompetencyPersonProjectAssessment competencyPersonProjectAssessment;
            ResidencyService <CompetencyPersonProjectAssessment> competencyPersonProjectAssessmentService = new ResidencyService <CompetencyPersonProjectAssessment>();

            ResidencyService <CompetencyPersonProjectAssessmentPointOfAssessment> competencyPersonProjectAssessmentPointOfAssessmentService = new ResidencyService <CompetencyPersonProjectAssessmentPointOfAssessment>();

            int competencyPersonProjectId = hfCompetencyPersonProjectId.ValueAsInt();

            if (competencyPersonProjectId == 0)
            {
                competencyPersonProject = new CompetencyPersonProject();
                competencyPersonProjectService.Add(competencyPersonProject, CurrentPersonId);
            }
            else
            {
                competencyPersonProject = competencyPersonProjectService.Get(competencyPersonProjectId);
            }

            int competencyPersonProjectAssessmentId = hfCompetencyPersonProjectAssessmentId.ValueAsInt();

            if (competencyPersonProjectAssessmentId == 0)
            {
                competencyPersonProjectAssessment = new CompetencyPersonProjectAssessment();
                competencyPersonProjectAssessmentService.Add(competencyPersonProjectAssessment, CurrentPersonId);
            }
            else
            {
                competencyPersonProjectAssessment = competencyPersonProjectAssessmentService.Get(competencyPersonProjectAssessmentId);
                competencyPersonProjectAssessment.CompetencyPersonProjectAssessmentPointOfAssessments = new List <CompetencyPersonProjectAssessmentPointOfAssessment>();
            }

            // set competencyPersonProjectAssessment.CompetencyPersonProjectId after saving competencyPersonProject in case it is new
            competencyPersonProjectAssessment.AssessmentDateTime = DateTime.Now;
            competencyPersonProjectAssessment.RatingNotes        = tbRatingNotesOverall.Text;
            competencyPersonProjectAssessment.AssessorPersonId   = hfAssessorPersonId.ValueAsInt();

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

            List <CompetencyPersonProjectAssessmentPointOfAssessment> competencyPersonProjectAssessmentPointOfAssessmentList = new List <CompetencyPersonProjectAssessmentPointOfAssessment>();

            foreach (RepeaterItem item in rptPointOfAssessment.Items.OfType <RepeaterItem>())
            {
                HiddenField hfProjectPointOfAssessmentId = item.FindControl("hfProjectPointOfAssessmentId") as HiddenField;
                int         projectPointOfAssessmentId   = hfProjectPointOfAssessmentId.ValueAsInt();

                CompetencyPersonProjectAssessmentPointOfAssessment competencyPersonProjectAssessmentPointOfAssessment = competencyPersonProjectAssessmentPointOfAssessmentService.Queryable()
                                                                                                                        .Where(a => a.ProjectPointOfAssessmentId == projectPointOfAssessmentId)
                                                                                                                        .Where(a => a.CompetencyPersonProjectAssessmentId == competencyPersonProjectAssessmentId).FirstOrDefault();

                if (competencyPersonProjectAssessmentPointOfAssessment == null)
                {
                    competencyPersonProjectAssessmentPointOfAssessment = new CompetencyPersonProjectAssessmentPointOfAssessment();
                    //// set competencyPersonProjectAssessmentPointOfAssessment.CompetencyPersonProjectAssessmentId = competencyPersonProjectAssessment.Id in save in case it's new
                    competencyPersonProjectAssessmentPointOfAssessment.ProjectPointOfAssessmentId = projectPointOfAssessmentId;
                }

                LabeledDropDownList ddlPointOfAssessmentRating = item.FindControl("ddlPointOfAssessmentRating") as LabeledDropDownList;
                TextBox             tbRatingNotesPOA           = item.FindControl("tbRatingNotesPOA") as TextBox;

                competencyPersonProjectAssessmentPointOfAssessment.Rating      = ddlPointOfAssessmentRating.SelectedValueAsInt();
                competencyPersonProjectAssessmentPointOfAssessment.RatingNotes = tbRatingNotesPOA.Text;

                competencyPersonProjectAssessmentPointOfAssessmentList.Add(competencyPersonProjectAssessmentPointOfAssessment);
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                competencyPersonProjectService.Save(competencyPersonProject, CurrentPersonId);
                competencyPersonProjectAssessment.CompetencyPersonProjectId = competencyPersonProject.Id;

                // set Overall Rating based on average of POA ratings
                competencyPersonProjectAssessment.OverallRating = (decimal?)competencyPersonProjectAssessmentPointOfAssessmentList.Average(a => a.Rating);
                competencyPersonProjectAssessmentService.Save(competencyPersonProjectAssessment, CurrentPersonId);

                foreach (var competencyPersonProjectAssessmentPointOfAssessment in competencyPersonProjectAssessmentPointOfAssessmentList)
                {
                    competencyPersonProjectAssessmentPointOfAssessment.CompetencyPersonProjectAssessmentId = competencyPersonProjectAssessment.Id;

                    if (competencyPersonProjectAssessmentPointOfAssessment.Id == 0)
                    {
                        competencyPersonProjectAssessmentPointOfAssessmentService.Add(competencyPersonProjectAssessmentPointOfAssessment, CurrentPersonId);
                    }

                    competencyPersonProjectAssessmentPointOfAssessmentService.Save(competencyPersonProjectAssessmentPointOfAssessment, CurrentPersonId);
                }
            });

            Rock.Model.Page page = null;
            string          personProjectDetailPageGuid = this.GetAttributeValue("PersonProjectDetailPage");

            if (!string.IsNullOrWhiteSpace(personProjectDetailPageGuid))
            {
                page = new PageService().Get(new Guid(personProjectDetailPageGuid));
            }

            if (page != null)
            {
                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["competencyPersonProjectId"] = hfCompetencyPersonProjectId.Value;
                NavigateToPage(page.Guid, qryString);
            }
            else
            {
                throw new Exception("PersonProjectDetailPage not configured correctly");
            }
        }
コード例 #20
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;
        }