/// <summary> /// Delete a Person record, and all dependent records. /// </summary> /// <param name="dataContext"></param> /// <param name="personId"></param> /// <returns></returns> private bool DeletePerson(RockContext dataContext, int personId) { var personService = new PersonService(dataContext); var person = personService.Get(personId); if (person == null) { return(false); } // Delete Person Views var personViewedService = new PersonViewedService(dataContext); var personViewedQuery = personViewedService.Queryable() .Where(x => x.TargetPersonAlias.PersonId == person.Id || x.ViewerPersonAlias.PersonId == person.Id); personViewedService.DeleteRange(personViewedQuery); // Delete Communications var communicationService = new CommunicationService(dataContext); var communicationQuery = communicationService.Queryable() .Where(x => x.SenderPersonAlias.PersonId == person.Id); communicationService.DeleteRange(communicationQuery); // Delete Communication Recipients var recipientsService = new CommunicationRecipientService(dataContext); var recipientsQuery = recipientsService.Queryable() .Where(x => x.PersonAlias.PersonId == person.Id); recipientsService.DeleteRange(recipientsQuery); // Delete Interactions var interactionService = new InteractionService(dataContext); var interactionQuery = interactionService.Queryable() .Where(x => x.PersonAlias.PersonId == person.Id); interactionService.DeleteRange(interactionQuery); // Delete Person Aliases var personAliasService = new PersonAliasService(dataContext); personAliasService.DeleteRange(person.Aliases); // Delete Person Search Keys var personSearchKeyService = new PersonSearchKeyService(dataContext); var searchKeys = person.GetPersonSearchKeys(dataContext); personSearchKeyService.DeleteRange(searchKeys); // Delete Person personService.Delete(person); return(true); }
/// <summary> /// Binds the grid. /// </summary> public void BindGrid() { int targetId = int.Parse(PageParameter("targetId")); int viewerId = int.Parse(PageParameter("viewerId")); bool viewedBy = Convert.ToBoolean(PageParameter("viewedBy")); var personViewedService = new PersonViewedService(new RockContext()); var personViewedList = personViewedService.Queryable() .Where(p => p.ViewerPersonAlias != null && p.ViewerPersonAlias.PersonId == viewerId && p.TargetPersonAlias != null && p.TargetPersonAlias.PersonId == targetId) .Select(p => new { Id = p.TargetPersonAlias.PersonId, Source = p.Source, TargetPerson = p.TargetPersonAlias.Person, ViewerPerson = p.ViewerPersonAlias.Person, ViewDateTime = p.ViewDateTime, IpAddress = p.IpAddress }).ToList(); if (viewedBy) { gridTitle.InnerText = string.Format( "{0} Viewed By {1}", personViewedList.Select(p => p.TargetPerson.FullName).FirstOrDefault(), personViewedList.Select(p => p.ViewerPerson.FullName).FirstOrDefault()); } else { gridTitle.InnerText = string.Format( "{0} Viewed {1}", personViewedList.Select(p => p.ViewerPerson.FullName).FirstOrDefault(), personViewedList.Select(p => p.TargetPerson.FullName).FirstOrDefault()); } SortProperty sortProperty = gViewDetails.SortProperty; if (sortProperty != null) { personViewedList = personViewedList.AsQueryable().Sort(sortProperty).ToList(); } else { personViewedList = personViewedList.OrderByDescending(p => p.ViewDateTime).ToList(); } gViewDetails.EntityTypeId = EntityTypeCache.Read <PersonViewed>().Id; gViewDetails.DataSource = personViewedList; gViewDetails.DataBind(); }
/// <summary> /// Execute method to write transaction to the database. /// </summary> public void Execute() { // store the view to the database if the viewer is NOT the target (don't track looking at your own record) if (ViewerPersonAliasId != TargetPersonAliasId) { var pvRecord = new PersonViewed(); pvRecord.TargetPersonAliasId = TargetPersonAliasId; pvRecord.ViewerPersonAliasId = ViewerPersonAliasId; pvRecord.ViewDateTime = DateTimeViewed; pvRecord.IpAddress = IPAddress; pvRecord.Source = Source; using (var rockContext = new Rock.Data.RockContext()) { var pvService = new PersonViewedService(rockContext); pvService.Add(pvRecord); rockContext.SaveChanges(); } } }
/// <summary> /// Execute method to write transaction to the database. /// </summary> public void Execute() { // store the view to the database if the viewer is NOT the target (don't track looking at your own record) if (ViewerPersonId != TargetPersonId) { using (new Rock.Data.UnitOfWorkScope()) { PersonViewedService pvService = new PersonViewedService(); PersonViewed pvRecord = new PersonViewed(); pvService.Add(pvRecord, null); pvRecord.IpAddress = IPAddress; pvRecord.TargetPersonId = TargetPersonId; pvRecord.ViewerPersonId = ViewerPersonId; pvRecord.ViewDateTime = DateViewed; pvRecord.Source = Source; pvService.Save(pvRecord, null); } } }
/// <summary> /// Binds the grid. /// </summary> protected void BindGrid() { var showProfilesViewed = GetAttributeValue("SeeProfilesViewed").AsBoolean(); var rockContext = new RockContext(); var personViewedService = new PersonViewedService(rockContext); var personService = new PersonService(rockContext); if (showProfilesViewed) { // This grid should show the profiles viewed by this person. pnlViewed.Visible = true; pnlViewedBy.Visible = false; if (personId.HasValue) { var viewedList = personViewedService.Queryable() .Where(p => p.ViewerPersonAlias != null && p.ViewerPersonAlias.PersonId == personId) .GroupBy(p => p.TargetPersonAlias.PersonId) .Select(p => new { TargetPersonId = p.Key, FirstViewed = p.Min(g => g.ViewDateTime), LastViewed = p.Max(g => g.ViewDateTime), ViewedCount = p.Count() }); var pQry = personService.Queryable(); var qry = viewedList .Join(pQry, v => v.TargetPersonId, p => p.Id, (v, p) => new { p.Id, FullName = p.NickName + " " + p.LastName, p.BirthDate, p.Gender, FirstViewedDate = v.FirstViewed, LastViewedDate = v.LastViewed, ViewedCount = v.ViewedCount }); SortProperty sortProperty = gViewed.SortProperty; if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderByDescending(q => q.LastViewedDate); } gViewed.EntityTypeId = EntityTypeCache.Read <PersonViewed>().Id; gViewed.DataSource = qry.ToList(); gViewed.DataBind(); } } else { // This grid should show the profiles that have viewed this person. pnlViewed.Visible = false; pnlViewedBy.Visible = true; if (personId.HasValue) { var viewedList = personViewedService.Queryable() .Where(p => p.TargetPersonAlias != null && p.TargetPersonAlias.PersonId == personId) .GroupBy(p => p.ViewerPersonAlias.PersonId) .Select(p => new { ViewerPersonId = p.Key, FirstViewed = p.Min(g => g.ViewDateTime), LastViewed = p.Max(g => g.ViewDateTime), ViewedCount = p.Count() }); var pQry = personService.Queryable(); var qry = viewedList .Join(pQry, v => v.ViewerPersonId, p => p.Id, (v, p) => new { p.Id, FullName = p.NickName + " " + p.LastName, p.BirthDate, p.Gender, FirstViewedDate = v.FirstViewed, LastViewedDate = v.LastViewed, ViewedCount = v.ViewedCount }); SortProperty sortProperty = gViewedBy.SortProperty; if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderByDescending(q => q.LastViewedDate); } gViewedBy.EntityTypeId = EntityTypeCache.Read <Person>().Id; gViewedBy.DataSource = qry.ToList(); gViewedBy.DataBind(); } } }
/// <summary> /// Execute method to write transaction to the database. /// </summary> public void Execute() { // store the view to the database if the viewer is NOT the target (don't track looking at your own record) if ( ViewerPersonId != TargetPersonId ) { using ( new Rock.Data.UnitOfWorkScope() ) { PersonViewedService pvService = new PersonViewedService(); PersonViewed pvRecord = new PersonViewed(); pvService.Add( pvRecord, null ); pvRecord.IpAddress = IPAddress; pvRecord.TargetPersonId = TargetPersonId; pvRecord.ViewerPersonId = ViewerPersonId; pvRecord.ViewDateTime = DateViewed; pvRecord.Source = Source; pvService.Save( pvRecord, null ); } } }