コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="results"></param>
        /// <param name="id"></param>
        /// <param name="version"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="ConcurrencyDomainException"></exception>
        /// <exception cref="NotFoundDomainException"></exception>
        public static async Task <T> GetWithConcurrencyCheckAsync <T>(IQueryable <T> results, Guid id, IConcurrencyVersion version) where T : IVersionedEntity
        {
            if (version == null)
            {
                throw new ConcurrencyDomainException();
            }

            try
            {
                T versionedEntity = await results.SingleOrDefaultAsync(e => e.Id == id);

                if (versionedEntity == null)
                {
                    throw new NotFoundDomainException($"Entity of type: {nameof(T)} not found with Id: {id}");
                }

                if (versionedEntity.Version != version.Version)
                {
                    throw new ConcurrencyDomainException(typeof(T), id, version);
                }

                return(versionedEntity);
            }
            catch (InvalidOperationException)
            {
                throw new ConcurrencyDomainException(typeof(T), id, version);
            }
        }
コード例 #2
0
 public ConcurrencyDomainException(MemberInfo type, Guid id, IConcurrencyVersion version, Exception innerException)
     : base(_formatConcurrencyException(type, id, version.Version), innerException)
 {
 }