public async Task<xcuda_Delivery_terms> Getxcuda_Delivery_termsByKey(string Delivery_terms_Id, List<string> includesLst = null, bool tracking = true) { try { if(string.IsNullOrEmpty(Delivery_terms_Id))return null; using ( var dbContext = new DocumentDSContext(){StartTracking = StartTracking}) { var i = Convert.ToInt32(Delivery_terms_Id); var set = AddIncludes(includesLst, dbContext); xcuda_Delivery_terms entity = await set.AsNoTracking().SingleOrDefaultAsync(x => x.Delivery_terms_Id == i).ConfigureAwait(continueOnCapturedContext: false); if(tracking && entity != null) entity.StartTracking(); return entity; } } 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); } }
public async Task<xcuda_Delivery_terms> Createxcuda_Delivery_terms(xcuda_Delivery_terms entity) { try { var res = (xcuda_Delivery_terms) entity; using ( var dbContext = new DocumentDSContext(){StartTracking = StartTracking}) { dbContext.xcuda_Delivery_terms.Add(res); await dbContext.SaveChangesAsync().ConfigureAwait(continueOnCapturedContext: false); res.AcceptChanges(); return res; } } 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); } }
public async Task<bool> Deletexcuda_Delivery_terms(string Delivery_terms_Id) { try { using ( var dbContext = new DocumentDSContext(){StartTracking = StartTracking}) { var i = Convert.ToInt32(Delivery_terms_Id); xcuda_Delivery_terms entity = await dbContext.xcuda_Delivery_terms .SingleOrDefaultAsync(x => x.Delivery_terms_Id == i) .ConfigureAwait(continueOnCapturedContext: false); if (entity == null) return false; dbContext.xcuda_Delivery_terms.Attach(entity); dbContext.xcuda_Delivery_terms.Remove(entity); await dbContext.SaveChangesAsync().ConfigureAwait(continueOnCapturedContext: false); return true; } } 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); } }
public async Task Savexcuda_Delivery_terms(xcuda_Delivery_terms i) { if (i == null) { return; } using (var ctx = new xcuda_Delivery_termsService()) { await ctx.Updatexcuda_Delivery_terms(i).ConfigureAwait(false); } }
public async Task<xcuda_Delivery_terms> Updatexcuda_Delivery_terms(xcuda_Delivery_terms entity) { using ( var dbContext = new DocumentDSContext(){StartTracking = StartTracking}) { try { var res = (xcuda_Delivery_terms) entity; if(res.TrackingState == TrackingState.Unchanged) res.TrackingState = TrackingState.Modified; dbContext.ApplyChanges(res); await dbContext.SaveChangesAsync().ConfigureAwait(continueOnCapturedContext: false); res.AcceptChanges(); return res; // var entitychanges = entity.ChangeTracker.GetChanges(); // if (entitychanges != null && entitychanges.FirstOrDefault() != null) // { // dbContext.ApplyChanges(entitychanges); // await dbContext.SaveChangesAsync().ConfigureAwait(continueOnCapturedContext: false); // entity.EntityId = entitychanges.FirstOrDefault().EntityId; // entity.AcceptChanges(); // } // return entity; } catch (DbUpdateConcurrencyException dce) { // Get failed entry foreach (var itm in dce.Entries) { if(itm.State != EntityState.Added) { var dv = itm.GetDatabaseValues(); if(dv != null) itm.OriginalValues.SetValues(dv); } } } 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) { if ( updateEx.Message.Contains( "The changes to the database were committed successfully, " + "but an error occurred while updating the object context")) return entity; 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); } } return entity; }