示例#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);
            }
        }
示例#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();
        }
示例#3
0
        public CYCA_TeamLeaderRightViewModel GetCareWorkersAndChildren()
        {
            var currentUser = (User)Session["CurrentUser"];
            var userId      = -1;

            if (currentUser != null)
            {
                userId = currentUser.User_Id;
            }
            var facilityID = employee.GetFacilityIdByUserID(userId);
            CYCA_TeamLeaderRightViewModel returnModel = new CYCA_TeamLeaderRightViewModel();

            returnModel.CareWorkers = new List <CareWorker>();
            var loggedInEmployee = employee.GetLoggedInEmployee(userId);

            var workers = careworker.GetCareWorkers(facilityID, loggedInEmployee.Employee_Id);
            List <CareWorker> careList = new List <CareWorker>();

            foreach (User u in workers)
            {
                var worker = new CareWorker();
                worker.FacilityId = facilityID;
                worker.Name       = u.First_Name + " " + u.Last_Name;
                worker.Desciption = "Care Worker";
                worker.Summary    = "Summary";
                worker.UserId     = u.User_Id;
                careList.Add(worker);
            }

            returnModel.CareWorkers.AddRange(careList);
            foreach (CareWorker t in returnModel.CareWorkers)
            {
                t.children = new List <CYCAChildAllocationViewModel>();
                t.children.AddRange(children.getCareWorkerChildren(facilityID, currentUser, t.UserId));
            }

            return(returnModel);
        }
示例#4
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                SetFilter();
                BindGrid();
            }
            else
            {
                var        rockContext = new RockContext();
                CareWorker item        = new CareWorkerService(rockContext).Get(hfCareWorkerId.ValueAsInt());
                if (item == null)
                {
                    item = new CareWorker();
                }
                item.LoadAttributes();

                phAttributes.Controls.Clear();
                Helper.AddEditControls(item, phAttributes, false, BlockValidationGroup, 2);
            }
        }
示例#5
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();
        }