Ejemplo n.º 1
0
        void lbRemoveMember_Click(object sender, EventArgs e)
        {
            Guid personGuid  = ((LinkButton)sender).ID.Substring(15).Replace("_", "-").AsGuid();
            var  groupMember = GroupMembers.Where(f => f.Person.Guid.Equals(personGuid)).FirstOrDefault();

            if (groupMember != null)
            {
                GroupMembers.Remove(groupMember);
                Duplicates.Remove(personGuid);
                if (!GroupMembers.Any())
                {
                    AddGroupMember();
                    CurrentPageIndex = 0;
                }
                CreateControls(true);
            }
        }
Ejemplo n.º 2
0
        protected void btnNext_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (CurrentPageIndex == 0)
                {
                    string locationKey = GetLocationKey();
                    if (!string.IsNullOrEmpty(locationKey) && !_verifiedLocations.ContainsKey(locationKey))
                    {
                        using (var rockContext = new RockContext())
                        {
                            var location = new LocationService(rockContext).Get(acAddress.Street1, acAddress.Street2, acAddress.City, acAddress.State, acAddress.PostalCode, acAddress.Country);
                            _verifiedLocations.AddOrIgnore(locationKey, (location != null ? location.Id : (int?)null));
                        }
                    }
                }

                if (CurrentPageIndex < (attributeControls.Count + 1))
                {
                    CurrentPageIndex++;
                    CreateControls(true);
                }
                else
                {
                    if (GroupMembers.Any())
                    {
                        if (CurrentPageIndex == (attributeControls.Count + 1) && FindDuplicates())
                        {
                            CurrentPageIndex++;
                            CreateControls(true);
                        }
                        else
                        {
                            var rockContext = new RockContext();

                            Guid?parentGroupGuid = GetAttributeValue("ParentGroup").AsGuidOrNull();

                            rockContext.WrapTransaction(() =>
                            {
                                Group group = null;
                                if (_isFamilyGroupType)
                                {
                                    group = GroupService.SaveNewFamily(rockContext, GroupMembers, cpCampus.SelectedValueAsInt(), true);
                                }
                                else
                                {
                                    group = GroupService.SaveNewGroup(rockContext, _groupType.Id, parentGroupGuid, tbGroupName.Text, GroupMembers, null, true);
                                }

                                if (group != null)
                                {
                                    string locationKey = GetLocationKey();
                                    if (!string.IsNullOrEmpty(locationKey) && _verifiedLocations.ContainsKey(locationKey))
                                    {
                                        GroupService.AddNewGroupAddress(rockContext, group, _locationType.Guid.ToString(), _verifiedLocations[locationKey]);
                                    }
                                }
                            });

                            Response.Redirect(string.Format("~/Person/{0}", GroupMembers[0].Person.Id), false);
                        }
                    }
                }
            }
        }