Esempio n. 1
0
        public virtual async Task <TOutput> SaveUpdatedWithOptimisticConcurrencyAsync <TOutput>(IHasRowVersion source, T destination, IPrincipal principal, Action <string, string> writeError, IDataAccessStrategy <T> savingStrategy = default)
        {
            savingStrategy = savingStrategy ?? dataAccessStrategy;

            savingStrategy.ThrowIfNull(nameof(savingStrategy));

            TOutput result = default;

            if (savingStrategy.CanUpdate(destination))
            {
                if (savingStrategy.CanUpdateAllProperties(destination))
                {
                    mapper.Map(source, destination);
                }
                else
                {
                    var properties = savingStrategy.GetPropertiesForUpdate(destination);

                    UpdateWithIncludeOrExcludeProperties(source, destination, true, properties);
                }

                bool success = await SaveUpdatedWithOptimisticConcurrencyAsync(destination, writeError, false);

                if (success)
                {
                    result = mapper.Map <TOutput>(destination);
                }
            }
            else
            {
                writeError("", Resources.ErrorMessages.AccessDenied);
            }

            return(result);
        }
Esempio n. 2
0
        public virtual Task <bool> SaveUpdatedWithOptimisticConcurrencyAsync(T entity, IPrincipal principal, Action <string, string> writeError, IDataAccessStrategy <T> savingStrategy = default)
        {
            savingStrategy = savingStrategy ?? dataAccessStrategy;

            savingStrategy.ThrowIfNull(nameof(savingStrategy));

            Task <bool> result;

            if (savingStrategy.CanUpdate(entity))
            {
                if (savingStrategy.CanUpdateAllProperties(entity))
                {
                    Update(entity);
                }
                else
                {
                    var properties = savingStrategy.GetPropertiesForUpdate(entity);

                    UpdateWithIncludeOrExcludeProperties(entity, true, properties);
                }

                result = SaveUpdatedWithOptimisticConcurrencyAsync(entity, writeError, false);
            }
            else
            {
                writeError("", Resources.ErrorMessages.AccessDenied);

                result = Task.FromResult(false);
            }

            return(result);
        }