protected virtual async Task <bool> OnBeforeInsert(GridCreateComponent <T> component)
 {
     if (BeforeInsert != null)
     {
         return(await BeforeInsert.Invoke(component, _item));
     }
     return(true);
 }
Exemple #2
0
        public virtual void InsertRange(params TModel[] models)
        {
            var eArgs = new RepositoryEventArgs <TModel>();

            eArgs.Models = models;

            BeforeInsert?.Invoke(eArgs);

            dbSet.AddRange(models);
        }
Exemple #3
0
        public virtual void Insert(TModel model)
        {
            var eArgs = new RepositoryEventArgs <TModel>();

            eArgs.Model = model;

            BeforeInsert?.Invoke(eArgs);

            dbSet.Add(model);
        }
Exemple #4
0
        /// <summary>
        /// Add a value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <ExecutionResult <T> > AddAsync(T value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var connectMessage = Connect();

            if (connectMessage != "OK")
            {
                throw new ConnectionException(connectMessage);
            }

            BeforeInsert?.Invoke(value);

            var stop = new Stopwatch();

            stop.Start();

            if (_diagnosticSource.IsEnabled($"{typeof(T).Name}_Add"))
            {
                _diagnosticSource.Write($"{typeof(T).Name}_Add", value);
            }

            _logger.LogTrace("Try to add");

            var key = FindKey();
            var id  = key.GetValue(value);

            var item = await _instance.SearchASingleItemAsync(x =>
            {
                var val = key.GetValue(x);
                return(val.Equals(id));
            });

            if (item == null)
            {
                item = await TryAdd(value);
            }
            else
            {
                throw new DuplicateNameException();
            }

            stop.Stop();

            _logger.LogTrace($"End Add in {stop.Elapsed}");

            AfterInsert?.Invoke(item);

            return(new ExecutionResult <T>(item != null, item));
        }
Exemple #5
0
 /// <summary>
 /// Raises the <see cref="E:BeforeInsert" /> event.
 /// </summary>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 protected virtual void OnBeforeInsert(OperatorEventArguments e)
 {
     BeforeInsert?.Invoke(this, e);
 }
Exemple #6
0
 internal bool OnBeforeInsert(object sender, IDbEntity dbEntity)
 {
     return(BeforeInsert?.Invoke(sender, dbEntity) ?? true);
 }