Example #1
0
 public Task <Contact> UpdateAsync(Contact value) => _ef.EventOutboxInvoker.InvokeAsync(this, async() =>
 {
     var __dataArgs = EfDbArgs.Create(_mapper);
     var __result   = await _ef.UpdateAsync <Contact, EfModel.Contact>(__dataArgs, Check.NotNull(value, nameof(value))).ConfigureAwait(false);
     _evtPub.PublishValue(__result, new Uri($"/contact/{_evtPub.FormatKey(__result)}", UriKind.Relative), $"Demo.Contact.{_evtPub.FormatKey(__result)}", "Update");
     return(__result);
 });
Example #2
0
 public Task <ContactCollectionResult> GetAllAsync() => DataInvoker.Current.InvokeAsync(this, async() =>
 {
     ContactCollectionResult __result = new ContactCollectionResult();
     var __dataArgs  = EfDbArgs.Create(_mapper);
     __result.Result = _ef.Query <Contact, EfModel.Contact>(__dataArgs, q => _getAllOnQuery?.Invoke(q, __dataArgs) ?? q).SelectQuery <ContactCollection>();
     return(await Task.FromResult(__result).ConfigureAwait(false));
 });
Example #3
0
 public Task DeleteAsync(Guid id) => _ef.EventOutboxInvoker.InvokeAsync(this, async() =>
 {
     var __dataArgs = EfDbArgs.Create(_mapper);
     await _ef.DeleteAsync <Contact, EfModel.Contact>(__dataArgs, id).ConfigureAwait(false);
     _evtPub.PublishValue(new Contact {
         Id = id
     }, new Uri($"/contact/{_evtPub.FormatKey(id)}", UriKind.Relative), $"Demo.Contact.{_evtPub.FormatKey(id)}", "Delete", id);
 });
Example #4
0
        /// <summary>
        /// Gets the entity for the specified <paramref name="keys"/> mapping from <typeparamref name="TModel"/> to <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The resultant <see cref="Type"/>.</typeparam>
        /// <typeparam name="TModel">The entity framework model <see cref="Type"/>.</typeparam>
        /// <param name="args">The <see cref="EfDbArgs"/>.</param>
        /// <param name="keys">The key values.</param>
        /// <returns>The entity value where found; otherwise, <c>null</c>.</returns>
        public async Task <T?> GetAsync <T, TModel>(EfDbArgs args, params IComparable[] keys) where T : class, new() where TModel : class, new()
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var efKeys = GetEfKeys(keys);

            return(await Invoker.InvokeAsync(this, async() =>
            {
                return await FindAsync <T, TModel>(args, efKeys).ConfigureAwait(false);
            }, this).ConfigureAwait(false));
        }
Example #5
0
        /// <summary>
        /// Performs a create for the value (reselects and/or automatically saves changes where specified).
        /// </summary>
        /// <typeparam name="T">The resultant <see cref="Type"/>.</typeparam>
        /// <typeparam name="TModel">The entity framework model <see cref="Type"/>.</typeparam>
        /// <param name="args">The <see cref="EfDbArgs"/>.</param>
        /// <param name="value">The value to insert.</param>
        /// <returns>The value (refreshed where specified).</returns>
        public async Task <T> CreateAsync <T, TModel>(EfDbArgs args, T value) where T : class, new() where TModel : class, new()
        {
            CheckSaveArgs <T, TModel>(args);

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value is IChangeLog cl)
            {
                if (cl.ChangeLog == null)
                {
                    cl.ChangeLog = new ChangeLog();
                }

                cl.ChangeLog.CreatedBy   = ExecutionContext.HasCurrent ? ExecutionContext.Current.Username : ExecutionContext.EnvironmentUsername;
                cl.ChangeLog.CreatedDate = ExecutionContext.HasCurrent ? ExecutionContext.Current.Timestamp : Cleaner.Clean(DateTime.Now);
            }

            return(await Invoker.InvokeAsync(this, async() =>
            {
                TModel model = args.Mapper.Map <T, TModel>(value, Mapper.OperationTypes.Create) ?? throw new InvalidOperationException("Mapping to the EF entity must not result in a null value.");

                // On create the tenant id must have a value specified.
                if (model is IMultiTenant mt)
                {
                    mt.TenantId = ExecutionContext.Current.TenantId;
                }

                DbContext.Add(model);

                if (args.SaveChanges)
                {
                    await DbContext.SaveChangesAsync(true).ConfigureAwait(false);
                }

                return args.Refresh ? args.Mapper.Map <TModel, T>(model, Mapper.OperationTypes.Get) ! : value;
            }, this).ConfigureAwait(false));
Example #6
0
 /// <summary>
 /// Creates an <see cref="EfDbQuery{T, TModel, TDbContext}"/> to enable select-like capabilities.
 /// </summary>
 /// <typeparam name="T">The resultant <see cref="Type"/>.</typeparam>
 /// <typeparam name="TModel">The entity framework model <see cref="Type"/>.</typeparam>
 /// <param name="args">The <see cref="EfDbArgs"/>.</param>
 /// <param name="query">The function to further define the query.</param>
 /// <returns>A <see cref="EfDbQuery{T, TModel, TDbContext}"/>.</returns>
 public IEfDbQuery <T, TModel> Query <T, TModel>(EfDbArgs args, Func <IQueryable <TModel>, IQueryable <TModel> >?query = null) where T : class, new() where TModel : class, new()
 => new EfDbQuery <T, TModel, TDbContext>(this, args, query);
Example #7
0
 private IQueryable <EfModel.Person> GetByArgsWithEfOnQuery(IQueryable <EfModel.Person> q, PersonArgs args, EfDbArgs efArgs)
 {
     _ef.WithWildcard(args?.FirstName, (w) => q = q.Where(x => EF.Functions.Like(x.FirstName, w)));
     _ef.WithWildcard(args?.LastName, (w) => q  = q.Where(x => EF.Functions.Like(x.LastName, w)));
     _ef.With(args?.Genders, () => q            = q.Where(x => args.Genders.ToGuidIdList().Contains(x.GenderId.Value)));
     return(q.OrderBy(x => x.LastName).ThenBy(x => x.FirstName));
 }
Example #8
0
        public async Task <RefDataNamespace.StatusCollection> StatusGetAllAsync()
        {
            var __coll = new RefDataNamespace.StatusCollection();
            await DataInvoker.Current.InvokeAsync(this, async() => { _ef.Query <RefDataNamespace.Status, EfModel.Status>(EfDbArgs.Create(_mapper)).SelectQuery(__coll); await Task.CompletedTask.ConfigureAwait(false); }, BusinessInvokerArgs.TransactionSuppress).ConfigureAwait(false);

            return(__coll);
        }
Example #9
0
 public Task <PerformanceReview?> GetAsync(Guid id) => DataInvoker.Current.InvokeAsync(this, async() =>
 {
     var __dataArgs = EfDbArgs.Create(_mapper);
     return(await _ef.GetAsync <PerformanceReview, EfModel.PerformanceReview>(__dataArgs, id).ConfigureAwait(false));
 });
Example #10
0
 public Task <Contact?> GetAsync(Guid id) => DataInvoker.Current.InvokeAsync(this, async() =>
 {
     var __dataArgs = EfDbArgs.Create(_mapper);
     return(await _ef.GetAsync <Contact, EfModel.Contact>(__dataArgs, id).ConfigureAwait(false));
 });