Ejemplo n.º 1
0
        /// <summary>
        /// Adds the New Worker
        /// </summary>
        private bool AddWorker(int careWorkerId, int personId)
        {
            if (Page.IsValid)
            {
                RockContext       rockContext       = new RockContext();
                CareWorkerService careWorkerService = new CareWorkerService(rockContext);

                CareWorker careWorker = null;

                if (!careWorkerId.Equals(0))
                {
                    careWorker = careWorkerService.Get(careWorkerId);
                }

                if (careWorker == null)
                {
                    careWorker = new CareWorker {
                        Id = 0
                    };
                }

                careWorker.Campuses = cpCampus.SelectedValues.AsDelimited(",");

                careWorker.PersonAliasId = ppNewPerson.PersonAliasId;

                careWorker.CategoryValues = dvpCategory.SelectedValues.AsDelimited(",");

                careWorker.IsActive = cbActive.Checked;

                careWorker.GeoFenceId = lpGeofenceLocation.Location?.Id;

                if (careWorker.IsValid)
                {
                    if (careWorker.Id.Equals(0))
                    {
                        careWorkerService.Add(careWorker);
                    }

                    // get attributes
                    careWorker.LoadAttributes();
                    Helper.GetEditValues(phAttributes, careWorker);

                    rockContext.WrapTransaction(() =>
                    {
                        rockContext.SaveChanges();
                        careWorker.SaveAttributeValues(rockContext);
                    });

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo 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)
        {
            var rockContext              = new RockContext();
            CareWorkerService service    = new CareWorkerService(rockContext);
            CareWorker        careWorker = service.Get(e.RowKeyId);

            if (careWorker != null)
            {
                service.Delete(careWorker);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="careWorkerId">The care worker identifier</param>
        public void ShowDetail(int careWorkerId)
        {
            CareWorker        careWorker        = null;
            var               rockContext       = new RockContext();
            CareWorkerService careWorkerService = new CareWorkerService(rockContext);

            if (!careWorkerId.Equals(0))
            {
                careWorker = careWorkerService.Get(careWorkerId);
                pdAuditDetails.SetEntity(careWorker, ResolveRockUrl("~"));
                cbActive.Checked = careWorker.IsActive;
            }
            else
            {
                cbActive.Checked = true;
            }

            if (careWorker == null)
            {
                careWorker = new CareWorker {
                    Id = 0
                };
                pdAuditDetails.Visible = false;
            }

            if (careWorker.Campuses.IsNotNullOrWhiteSpace())
            {
                cpCampus.SelectedCampusIds = careWorker.Campuses.SplitDelimitedValues(",").Select(c => c.AsInteger()).ToList();
            }
            else
            {
                cpCampus.ClearSelection();
            }

            if (careWorker.PersonAlias != null)
            {
                ppNewPerson.SetValue(careWorker.PersonAlias.Person);
            }
            else
            {
                ppNewPerson.SetValue(null);
            }

            dvpCategory.DefinedTypeId = DefinedTypeCache.Get(new Guid(rocks.kfs.StepsToCare.SystemGuid.DefinedType.CARE_NEED_CATEGORY)).Id;

            if (careWorker.CategoryValues.IsNotNullOrWhiteSpace())
            {
                dvpCategory.SetValues(careWorker.CategoryValues.SplitDelimitedValues(","));
            }
            else
            {
                dvpCategory.ClearSelection();
            }

            if (careWorker.GeoFenceId != null)
            {
                var location = new LocationService(rockContext).Get(careWorker.GeoFenceId.Value);
                lpGeofenceLocation.SetBestPickerModeForLocation(location);
                lpGeofenceLocation.Location = location;
            }
            else
            {
                lpGeofenceLocation.Location = null;
            }

            careWorker.LoadAttributes();
            Helper.AddEditControls(careWorker, phAttributes, true, BlockValidationGroup, 2);

            ppPerson_SelectPerson(null, null);

            hfCareWorkerId.Value = careWorker.Id.ToString();
        }