/// <summary> /// Gets a dictionary that contains all the Campuses from RockRMS. The dictionary will be cached in memory for up to 5 minutes. /// </summary> /// <param name="resetCache">A <see cref="System.Boolean"/> that indicates if the Campus Cache should be reset. Defaults to false.</param> /// <returns> /// A <see cref="System.Collections.Generic.Dictionary(int,object)" /> that contains all the campuses in Rock. The key value is the Rock instance Id of the Campus /// and the value is a <see cref="System.Collections.Generic.Dictionary(String,Object)" /> containing the entity The key value represents a property name and the /// value represents the value of the entity. /// </returns> public Dictionary<int, Dictionary<string, object>> GetCampuses(bool resetCache = false) { const string campusCacheKey = "CampusCache"; Dictionary<int, Dictionary<string, object>> campuses = null; ObjectCache cache = MemoryCache.Default; CacheItemPolicy policy = new CacheItemPolicy(); policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes( 5 ); if ( !resetCache ) { campuses = ( cache[campusCacheKey] as Dictionary<int, Dictionary<string, object>> ); } if ( resetCache || campuses == null ) { campuses = new Dictionary<int, Dictionary<string, object>>(); CampusController controller = new CampusController( Service ); List<Campus> campusList = controller.GetAll(); foreach ( var campus in campusList ) { campuses.Add( campus.Id, ToDictionary( campus ) ); } cache.Set( campusCacheKey, campuses, policy ); } return campuses; }
public CampusControllerTest() { _campusServiceMock = Substitute.For <ICampusService>(); _campusController = new CampusController(_campusServiceMock); }
/// <summary> /// Saves a Campus to the Rock instance. If the <see cref="campusId"/> is null, an add will be attempted, otherwise an update will be attempted. /// </summary> /// <param name="isSystem">A <see cref="System.Boolean"/> value that is <c>true<c> if the Campus is a system generated value.</param> /// <param name="name">A <see cref="System.String"/> representing the unique name of the campus..</param> /// <param name="shortCode">A <see cref="System.String"/> representing the optional short code for the campus. Defaults to null.</param> /// <param name="locationId">A nullable <see cref="System.Int32"/> that represents the LcoationId of the <see cref="Rock.Model.Location"/> that is associated with the campus. Defaults to null.</param> /// <param name="phoneNumber">A <see cref="System.String"/> representing the phone number of the campus. Defaults to null.</param> /// <param name="leaderPersonAliasId">A <see cref="System.Int32"/> that represents the PersonAliasId of a <see cref="Rock.Model.PersonAlias"/> that is associated with the <see cref="Rock.Model.Person"/> /// who is the leader of the campus.</param> /// <param name="serviceTimes">A <see cref="System.String"/> representing a delimited list of service times for the campus.</param> /// <param name="foreignId">A <see cref="System.String"/> representing the identifier of the Campus in the foreign system that it was imported from.</param> /// <param name="campusId">A nullable <see cref="System.Int32"/> representing the internal Campus Identifier (primary key) of the campus. This will allow for the support of updates.</param> /// <returns>A nullable <see cref="System.Int32"/> representing the Id of the campus that was either added or updated. Will be null if an update is attempted and the campus was not found. </returns> public int? SaveCampus(bool isSystem, string name, string shortCode = null, int? locationId = null, string phoneNumber = null, int? leaderPersonAliasId = null, string serviceTimes = null, string foreignId = null, int? campusId = null ) { Campus c = null; CampusController controller = new CampusController( Service ); if ( campusId == null || campusId <= 0 ) { c = new Campus(); } else { c = controller.GetById( (int)campusId ); } // Update was attempted and campus was not found in Arena instance. if ( c == null ) { return null; } c.IsSystem = isSystem; c.Name = name; c.ShortCode = shortCode; c.LocationId = locationId; c.LeaderPersonAliasId = leaderPersonAliasId; c.PhoneNumber = phoneNumber; c.ServiceTimes = serviceTimes; c.ForeignId = foreignId; c.IsActive = true; if ( c.Id > 0 ) { c.ModifiedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId; controller.Update(c); } else { c.CreatedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId; controller.Add( c ); } c = controller.GetByGuid( c.Guid ); GetCampuses( true ); return c.Id; }