public GetByAliasId ( int aliasPersonId ) : PersonAlias | ||
aliasPersonId | int | The alias person identifier. |
Результат | PersonAlias |
public virtual PersonAlias GetByAliasId( int aliasPersonId )
{
var personAlias = Queryable( "Person" ).Where( a => a.AliasPersonId == aliasPersonId ).FirstOrDefault();
if ( personAlias != null )
{
return personAlias;
}
else
{
// If the personId is valid, there should be a personAlias with the AliasPersonID equal
// to that personId. If there isn't for some reason, create it now.
var person = new PersonService( (RockContext)this.Context ).Get( aliasPersonId );
if ( person != null )
{
personAlias = new PersonAlias();
personAlias.Guid = Guid.NewGuid();
personAlias.AliasPersonId = person.Id;
personAlias.AliasPersonGuid = person.Guid;
personAlias.PersonId = person.Id;
// Use a different context so calling method's changes are not yet saved
var rockContext = new RockContext();
new PersonAliasService( rockContext ).Add( personAlias );
rockContext.SaveChanges();
return Get( personAlias.Id );
}
}
return null;
}
public void SaveStars(DateTime dt, int paId, decimal starsValue, string note) { StarsProjectContext starsProjectContext = new StarsProjectContext(); StarsService starsService = new StarsService(starsProjectContext); org.newpointe.Stars.Model.Stars stars = new org.newpointe.Stars.Model.Stars(); PersonAliasService personAliasService = new PersonAliasService(new RockContext()); int campusId = personAliasService.GetByAliasId(paId).Person.GetCampus().Id; stars.PersonAliasId = paId; stars.CampusId = campusId; stars.TransactionDateTime = DateTime.Now; stars.Value = starsValue; stars.Note = note; starsService.Add(stars); starsProjectContext.SaveChanges(); }