Beispiel #1
0
        public DataConflictException(string errorType, DataConflictInfo info)
            : base(errorType, "Data conflict (Optimistic concurrency)")
        {
            BaseDbModel dbValues = (BaseDbModel)info.DatabaseValues.ToObject();
            BaseDbModel cValues  = (BaseDbModel)info.CurrentValues.ToObject();

            this.DatabaseValues = dbValues;
            this.CurrentValues  = cValues;
        }
Beispiel #2
0
        protected async Task <SaveResult> SaveAsync(DataConflictPolicy policy)
        {
            bool saveFailed;

            do
            {
                saveFailed = false;

                try
                {
                    int result = await this.context.SaveChangesAsync();

                    return(new SaveResult {
                        AlteredObjectsCount = result
                    });
                }
                catch (DbUpdateConcurrencyException exception)
                {
                    if (policy == DataConflictPolicy.NoPolicy)
                    {
                        throw new DalException(DalErrorType.BaseServiceDataConflictWithNoPolicy,
                                               "Data conflict (Optimistic concurrency)");
                    }

                    saveFailed = true;

                    DataConflictInfo info = OptimisticConcurrency.ApplyPolicy(policy, exception);
                    if (info != null)
                    {
                        throw new DataConflictException(DalErrorType.BaseServiceDataConflictWithAskClientPolicy, info);
                    }
                }
                catch (Exception exception)
                {
                    exception.HandleException();
                }
            } while (saveFailed);

            return(null);
        }
Beispiel #3
0
 public SaveResult()
 {
     this.AlteredObjectsCount = 0;
     this.AlteredIds          = new int[] { };
     this.DataConflictInfo    = null;
 }