public async Task <bool> Add(DestinationEntity entity) { try { Connection = await UnitOfWork.GetConnectionAsync(); DynamicParameters parameters = new DynamicParameters(); parameters.Add("@DestinationId", entity.DestinationId); parameters.Add("@Name", entity.Name); parameters.Add("@IsDeleted", false); var affectedRecords = await SqlMapper.ExecuteAsync(Connection, DESTINATION_INSERT, parameters, Transaction, commandType : StoredProcedure).ConfigureAwait(false); return(affectedRecords == 1); } catch (AggregateException aggException) { throw new Exception(aggException.Message); } catch (SqlException sqlException) { throw new Exception(sqlException.Message); } catch (Exception exception) { throw exception; } }
/// <summary> /// Distributes the elements from <paramref name="Source"/> among <paramref name="Destination"/>. /// The method "Accumulate" is called once on each element in <paramref name="Destination"/>. /// </summary> /// <typeparam name="AccumulatedT"></typeparam> /// <typeparam name="SharedT"></typeparam> /// <typeparam name="DestEntityT"></typeparam> /// <param name="Source"></param> /// <param name="Shared"></param> /// <param name="Destination"></param> /// <returns>subset of <paramref name="Source"/> which was not assigned to elements in <paramref name="Destination"/>.</returns> static public IEnumerable <PropertyGenTimespanInt64 <AccumulatedT> > Distribute <AccumulatedT, SharedT, DestEntityT>( this IEnumerable <PropertyGenTimespanInt64 <AccumulatedT> > Source, SharedT Shared, ICollection <DestEntityT> Destination) where DestEntityT : EntityScoring <AccumulatedT, SharedT> { if (null == Destination) { return(Source); } var SourceInstantConsumed = new HashSet <PropertyGenTimespanInt64 <AccumulatedT> >(); var DestinationEntityFed = new HashSet <DestEntityT>(); var SourceRendered = Source?.ToArray(); var SetCombination = Destination?.SelectMany(DestinationEntity => SourceRendered ?.WhereNotDefault() ?.Select(SourceInstant => new { SourceInstant, DestinationEntity, Score = DestinationEntity?.Score(SourceInstant.Value, Shared) ?? int.MinValue })) ?.OrderByDescending(Combi => Combi.Score) ?.ToArray(); foreach (var Combination in SetCombination) { if (!(0 < Combination.Score)) { break; } if (SourceInstantConsumed.Contains(Combination.SourceInstant)) { continue; } if (DestinationEntityFed.Contains(Combination.DestinationEntity)) { continue; } Combination.DestinationEntity.Accumulate(Combination.SourceInstant, Shared); SourceInstantConsumed.Add(Combination.SourceInstant); DestinationEntityFed.Add(Combination.DestinationEntity); } return(SourceRendered.Except(SourceInstantConsumed)); }