internal async Task RemoveSelectedItems(IEnumerable <int> lst)
        {
            try
            {
                int ASYCUDA_Id = 0;
                using (var ctx = new DocumentItemDSContext()
                {
                    StartTracking = true
                })
                {
                    foreach (var item_id in lst)
                    {
                        var item =
                            ctx.xcuda_Item.Include(x => x.xcuda_PreviousItem).FirstOrDefault(x => x.Item_Id == item_id);
                        if (item != null)
                        {
                            if (ASYCUDA_Id == 0)
                            {
                                ASYCUDA_Id = item.ASYCUDA_Id;
                            }
                            ctx.xcuda_Item.Remove(item);
                        }
                    }



                    ctx.SaveChanges();
                }
                await ReorderDocumentItems(ASYCUDA_Id);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        private void UpdateEntity(xcuda_Item entity)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew,
                                                    new TransactionOptions()
            {
                IsolationLevel = IsolationLevel.ReadUncommitted
            }))
            {
                using (var dbContext = new DocumentItemDSContext())
                {
                    try
                    {
                        dbContext.ApplyChanges(entity);
                        dbContext.SaveChanges();
                        //entity.AcceptChanges();
                        scope.Complete();
                    }
                    catch (DbUpdateConcurrencyException dce)
                    {
                        // Get failed entry
                        foreach (var itm in dce.Entries)
                        {
                            itm.OriginalValues.SetValues(itm.GetDatabaseValues());
                        }
                    }
                    catch (OptimisticConcurrencyException oce)
                    {
                        var context = ((IObjectContextAdapter)dbContext).ObjectContext;

                        foreach (var entry in oce.StateEntries)
                        {
                            context.Refresh(System.Data.Entity.Core.Objects.RefreshMode.StoreWins, entry.Entity);
                        }
                    }
                    catch (DbUpdateException e)
                    {
                        // Debugger.Break();
                        SqlException s = e.InnerException.InnerException as SqlException;
                        if (s != null && s.Number == 2627)
                        {
                        }
                        else
                        {
                            Debugger.Break();
                            throw;
                        }
                    }
                    catch (Exception updateEx)
                    {
                        System.Diagnostics.Debugger.Break();
                        //throw new FaultException(updateEx.Message);
                        var fault = new ValidationFault
                        {
                            Result      = false,
                            Message     = updateEx.Message,
                            Description = updateEx.StackTrace
                        };
                        throw new FaultException <ValidationFault>(fault);
                    }
                }
            }
        }