public bool Remove(params T[] items) { try { using (var context = new anketbazEntities()) { foreach (T item in items) { context.Entry(item).State = System.Data.EntityState.Deleted; } context.SaveChanges(); } return(true); } catch (Exception ex) { Log.Log.Error(ex.Message); return(false); } }
public bool Add(params T[] items) { try { using (var context = new anketbazEntities()) { foreach (T item in items) { if (CrtimProperty != null) { CrtimProperty.SetValue(item, DateTime.Now.ToStringHhmmss(), null); } if (CrdatProperty != null) { CrdatProperty.SetValue(item, DateTime.Now.ToStringYyyyMMdd(), null); } context.Entry(item).State = System.Data.EntityState.Added; } context.SaveChanges(); } return(true); } catch (DbEntityValidationException ex) { string errorMessage = string.Empty; foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { if (!dbEntityValidationResult.IsValid) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { errorMessage += string.Format("{0} : {1} \n", dbValidationError.ErrorMessage, dbValidationError.PropertyName); } } } Log.Log.Error(ex.Message + errorMessage); return(false); } }