Exemplo n.º 1
0
        /// <summary>
        /// Synchronizes names for an event, including possible names inherited from the series.
        /// </summary>
        /// <param name="ctx">Database context. Cannot be null.</param>
        /// <param name="ev">Event to be updated. Cannot be null.</param>
        /// <param name="seriesLink">Linked series. Can be null.</param>
        /// <param name="customName">Whether event uses custom name.</param>
        /// <param name="seriesNumber">Series number.</param>
        /// <param name="seriesSuffix">Series suffix.</param>
        /// <param name="nameContracts">Given names for event.</param>
        /// <returns>True if the names were changed, otherwise false.</returns>
        /// <exception cref="DuplicateEventNameException">If duplicate names are detected.</exception>
        /// <remarks>
        /// If series is specified and custom name setting is disabled, then event names are generated based on series names.
        /// If custom name is enabled or no series is specified, given names are used.
        /// Default name language is inherited from series as well, but that setting is not touched by this method.
        /// </remarks>
        public bool UpdateNames(IDatabaseContext ctx, ReleaseEvent ev, IEntryWithIntId seriesLink,
                                bool customName, int seriesNumber, string seriesSuffix, IEnumerable <ILocalizedString> nameContracts)
        {
            var names       = GetNames(ctx, seriesLink, customName, seriesNumber, seriesSuffix, nameContracts).ToArray();
            var namesValues = names.Select(n => n.Value).ToArray();

            CheckDuplicateName(ctx, namesValues, ev.Id);
            var changed = SaveNames(ctx, ev, names);

            return(changed);
        }
Exemplo n.º 2
0
        private IEnumerable <ILocalizedString> GetNames(IDatabaseContext ctx,
                                                        IEntryWithIntId seriesLink, bool customName, int seriesNumber, string seriesSuffix, IEnumerable <ILocalizedString> nameContracts)
        {
            var series = ctx.NullSafeLoad <ReleaseEventSeries>(seriesLink);

            var names = series != null && !customName
                                ? series.Names.Select(seriesName =>
                                                      new LocalizedStringContract(series.GetEventName(seriesNumber, seriesSuffix, seriesName.Value), seriesName.Language))
                                : nameContracts;

            return(names);
        }
Exemplo n.º 3
0
 public static int IdOrDefault(this IEntryWithIntId entry)
 {
     return(entry != null ? entry.Id : 0);
 }
Exemplo n.º 4
0
 public static bool IdEquals(this IEntryWithIntId left, IEntryWithIntId right)
 {
     return(left.Id == right.Id);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Compares the Id of this entry with another.
 /// Null values and entries where the Id is undefined (0) will be handled.
 /// </summary>
 /// <param name="left">First entry to be compared. Can be null.</param>
 /// <param name="right">Second entry to be compared. Can be null.</param>
 /// <returns>True if entries on both sides are equal.</returns>
 /// <remarks>
 /// Null values and entries with undefined (0) Id will be considered equal.
 /// That means,
 /// null + 0 == true
 /// null + null == true
 /// 0 + 0 == true
 /// 39 + 39 == true
 /// null + 39 == false
 /// 0 + 39 == false
 /// </remarks>
 public static bool NullSafeIdEquals(this IEntryWithIntId left, IEntryWithIntId right)
 {
     return(left.IdOrDefault() == right.IdOrDefault());
 }
Exemplo n.º 6
0
 public static T NullSafeLoad <T>(this IDatabaseContext <T> ctx, IEntryWithIntId entry)
 {
     return(entry != null && entry.Id != 0 ? ctx.Load(entry.Id) : default);
Exemplo n.º 7
0
 public static T LoadEntry <T>(this IDatabaseContext ctx, IEntryWithIntId entry) where T : class, IDatabaseObject
 => ctx.Load <T>(entry.Id);
Exemplo n.º 8
0
 public static T LoadEntry <T>(this IDatabaseContext ctx, IEntryWithIntId entry) => ctx.Load <T>(entry.Id);
Exemplo n.º 9
0
 /// <summary>
 /// Loads an entry based on a reference, or returns null if the reference is null or points to an entry that shouldn't exist (Id is 0).
 /// </summary>
 /// <typeparam name="T">Type of entry to be loaded.</typeparam>
 /// <param name="ctx">Repository context. Cannot be null.</param>
 /// <param name="entry">Entry reference. Can be null in which case null is returned.</param>
 /// <returns>Reference to the loaded entry. Can be null if <paramref name="entry"/> is null or Id is 0.</returns>
 public static T NullSafeLoad <T>(this IRepositoryContext <T> ctx, IEntryWithIntId entry)
 {
     return(entry != null && entry.Id != 0 ? ctx.Load(entry.Id) : default(T));
 }
Exemplo n.º 10
0
		public static bool IdEquals(this IEntryWithIntId left, IEntryWithIntId right) {
			return left.Id == right.Id;
		}
Exemplo n.º 11
0
		/// <summary>
		/// Compares the Id of this entry with another.
		/// Null values and entries where the Id is undefined (0) will be handled.
		/// </summary>
		/// <param name="left">First entry to be compared. Can be null.</param>
		/// <param name="right">Second entry to be compared. Can be null.</param>
		/// <returns>True if entries on both sides are equal.</returns>
		/// <remarks>
		/// Null values and entries with undefined (0) Id will be considered equal.
		/// That means, 
		/// null + 0 == true
		/// null + null == true
		/// 0 + 0 == true
		/// 39 + 39 == true
		/// null + 39 == false
		/// 0 + 39 == false
		/// </remarks>
		public static bool NullSafeIdEquals(this IEntryWithIntId left, IEntryWithIntId right) {

			return left.IdOrDefault() == right.IdOrDefault();
			
		}
Exemplo n.º 12
0
 public static bool IsNullOrDefault(this IEntryWithIntId entry)
 {
     return(entry == null || entry.Id == 0);
 }