public IGenericBusinessObj GetRelation(System.Data.Objects.DataClasses.IEntityWithRelationships currentObject, System.Data.Objects.ObjectStateEntry currentState) { System.Data.Objects.DataClasses.IRelatedEnd currentEnd = GetRelatedEnd(currentObject); if (currentEnd == null) { throw new ApplicationException(string.Format("Could not find {0} on {1}", TargetRoleName, RelationshipName)); } // loaded from DB then call load check to see if loaded before enumerating if (currentState.State == System.Data.EntityState.Modified || currentState.State == System.Data.EntityState.Unchanged) { if (currentEnd.IsLoaded == false) { return(null); } } // find the first one and return it foreach (object childObject in currentEnd) { return(childObject as IGenericBusinessObj); } // if first not found then return return(null); }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { AlabanzaMiembroDiaNoDisponible entidad = (AlabanzaMiembroDiaNoDisponible)entry.Entity; validarFechas(entidad); validarEnsayosYEventos(entidad); }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { Celula entidadActual = ((Celula)entry.Entity); validarDescripcion(entidadActual); validarUnicidad(entidadActual); }
protected static void SoftDelete(Helpers.ApiContext apiContext, System.String entitySet, System.Collections.Generic.IEnumerable <Entities.EntityObject> entities) { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; foreach (var entity in entities) { System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity); System.Guid id = (System.Guid)ose.CurrentValues["Id"]; System.Guid modifiedBy = (System.Guid)ose.CurrentValues["ModifiedBy"]; System.DateTime modifiedOn = (System.DateTime)ose.CurrentValues["ModifiedOn"]; System.DateTime origModifiedOn = (System.DateTime)ose.OriginalValues["ModifiedOn"]; string sqlQuery = string.Format(@"UPDATE [{0}] SET [IsDeleted] = 1, [ModifiedBy] = '{1}', [ModifiedOn] = '{2}' WHERE [Id] = @p0 AND [ModifiedOn] = @p1", entitySet, modifiedBy, modifiedOn); int recordCount = apiContext.CurrentContext.ExecuteStoreCommand(sqlQuery, id, origModifiedOn); if (recordCount == 0) { throw new System.Data.OptimisticConcurrencyException(); } } }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { AlabanzaEnsayoMiembro entidad = (AlabanzaEnsayoMiembro)entry.Entity; establecerAsistenciaSegunRetraso(entidad); establecerValoresIniciales(entry); }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { AlabanzaEnsayo entidad = (AlabanzaEnsayo)entry.Entity; validarAsistenciaSegunFecha(entidad); validarHoras(entidad); }
/// <summary> /// Set CustomerId, ModifiedBy and ModifiedOn properties modified for update/delete /// </summary> /// <param name="apiContext"></param> /// <param name="entity"></param> protected static void SetSystemPropertiesModified(Helpers.ApiContext apiContext, Entities.EntityObject entity) { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity); ose.SetModifiedProperty("ModifiedBy"); ose.SetModifiedProperty("ModifiedOn"); ose.SetModifiedProperty("CustomerId"); }
void SetTransactionDescription(System.Data.Objects.ObjectStateEntry entry) { Transaction transaction = entry.Entity as Transaction; if (transaction != null) { // Your code } }
private void establecerValoresIniciales(System.Data.Objects.ObjectStateEntry entry) { AlabanzaEnsayoMiembro entidad = (AlabanzaEnsayoMiembro)entry.Entity; if (entry.State == System.Data.EntityState.Added) { entidad.Asistencia = false; entidad.Retraso = false; } }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { ConsolidacionBoleta entidad = (ConsolidacionBoleta)entry.Entity; Validaciones.ValidarEmail(entidad.Email); validarEstatus(entidad); establecerEdad(entidad); establecerCategoria(entidad); validarUnicidad(entry); }
/// <summary> /// No Metadata Documentation available. /// </summary> /// <param name="apiContext"></param> /// <param name="users"></param> /// <returns></returns> public static Helpers.ActionResult UpdateStatus(Helpers.ApiContext apiContext, System.Collections.Generic.IEnumerable <Entities.User> users) { // API doesn't allow null parameters. This method requires at least 1 item in the collection. if (apiContext == null) { throw new System.ArgumentNullException("apiContext"); } if (users == null) { throw new System.ArgumentNullException("users"); } if (users.Count() == 0) { throw new System.ArgumentOutOfRangeException("users"); } // Verify user is authorized to perform action, otherwise throw exception. Security.SecurityHandler.SetApiContext(apiContext); Helpers.ActionResult result = Helpers.ActionResult.Factory(true); try { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; foreach (Entities.User user in users) { // ATTACH object AttachObject(apiContext, "Users", user); // SET system level properties SetSystemProperties(apiContext, user); SetSystemPropertiesModified(apiContext, user); // SET IsActive property modified System.Data.Objects.ObjectStateEntry ose = apiContext.CurrentContext.ObjectStateManager.GetObjectStateEntry(user); ose.SetModifiedProperty("IsActive"); } context.SaveChanges(); // Save Changes DetachObjects(apiContext, users); // Clean ObjectState cache } catch (System.Data.OptimisticConcurrencyException ex) { object forDebugging = ex; //HandleOptimisticConcurrencyException(apiContext, users, ex, ref result); //throw Helpers.Exceptions.OptimisticConcurrencyException.Factory(ex); throw; } catch (System.Exception ex) { object forDebugging = ex; throw; // Helpers.Exceptions.UpdateEntityException.Factory(ex); } return(result); }
/// <summary> /// SetDeleted for SoftDelete /// </summary> /// <param name="apiContext"></param> /// <param name="entity"></param> protected static void SetDeleted(Helpers.ApiContext apiContext, Entities.EntityObject entity) { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; // SET IsDeleted = true entity.GetType().GetProperty("IsDeleted").SetValue(entity, true, null); // SET IsDeleted modified System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity); ose.SetModifiedProperty("IsDeleted"); }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { Miembro entidad = (Miembro)entry.Entity; Validaciones.ValidarEmail(entidad.Email); validarConyuge(entidad); validarTelefonos(entidad); validarPassword(entidad); validarLiderzagoDeMiembro(entidad); validarUnicidad(entry); }
/// <summary> /// Determina si un campo especifico fue modificado en cierta entidad /// </summary> /// <returns>TRUE = el campo especificado si fue modificado; FALSE = el campo especificado se quedo igual</returns> public static bool ValidarCambiosEnCampo(System.Data.Objects.ObjectStateEntry entidad, string nombreDelCampo) { for (int i = 0; i < entidad.OriginalValues.FieldCount; i++) { if (entidad.OriginalValues.GetName(i).Equals(nombreDelCampo, StringComparison.OrdinalIgnoreCase)) { if (!entidad.OriginalValues.GetString(i).Equals(entidad.CurrentValues.GetString(i), StringComparison.OrdinalIgnoreCase)) { return(true); } else { return(false); } } } return(false); }
private void validarUnicidad(System.Data.Objects.ObjectStateEntry entry) { // Validamos si no existe ya una boleta con el mismo correo ConsolidacionBoleta entidadPreexistente = (from o in SesionActual.Instance.getContexto <IglesiaEntities>().ConsolidacionBoleta where o.Email == ((ConsolidacionBoleta)entry.Entity).Email select o).SingleOrDefault(); if (entidadPreexistente != null) { string registroExistenteMsg = string.Format("Ya existe una boleta para ese email [{0}], la cual su ID es [{1}]. De ser necesario, buscarla y modificarla o utilizar un email distinto.", entidadPreexistente.Email, entidadPreexistente.Id); if (entry.State == System.Data.EntityState.Added) { throw new ExcepcionReglaNegocio(registroExistenteMsg); } else if (entry.State == System.Data.EntityState.Modified) { if (Validaciones.ValidarCambiosEnCampo(entry, "email")) { throw new ExcepcionReglaNegocio(registroExistenteMsg); } } } }
private void validarUnicidad(System.Data.Objects.ObjectStateEntry entry) { Miembro entidadActual = ((Miembro)entry.Entity); // Validamos si no existe ya un miembro con el mismo correo Miembro entidadPreexistente = (from o in SesionActual.Instance.getContexto <IglesiaEntities>().Miembro where o.Email == entidadActual.Email select o).SingleOrDefault(); if (entidadPreexistente != null) { string registroExistenteMsg = string.Format("Ya existe algún miembro registrado con ese email [{0}] cuyo Id es [{1}] y el cual se encuentra asignado a la célula [{2}] [{3}].", entidadPreexistente.Email, entidadPreexistente.MiembroId, entidadPreexistente.Celula.Descripcion, entidadPreexistente.CelulaId); if (entry.State == System.Data.EntityState.Added) { if (entidadPreexistente.Borrado == false) { throw new ExcepcionReglaNegocio(registroExistenteMsg); } else { // Modificamos la entidad BORRADA con los nuevos datos, en vez de crear una nueva entidadActual.MiembroId = entidadPreexistente.MiembroId; SesionActual.Instance.getContexto <IglesiaEntities>().Miembro.Detach(entidadActual); SesionActual.Instance.getContexto <IglesiaEntities>().ObjectStateManager.ChangeObjectState(entidadActual, System.Data.EntityState.Detached); System.Data.Objects.ObjectStateEntry state = SesionActual.Instance.getContexto <IglesiaEntities>().ObjectStateManager.GetObjectStateEntry(entidadPreexistente); state.ApplyCurrentValues(entidadActual); state.ChangeState(System.Data.EntityState.Modified); } } else if (entry.State == System.Data.EntityState.Modified) { if (Validaciones.ValidarCambiosEnCampo(entry, "email")) { throw new ExcepcionReglaNegocio(registroExistenteMsg); } } } }
/// <summary> /// SetModified for Update /// </summary> /// <param name="apiContext"></param> /// <param name="entity"></param> protected static void SetModified(Helpers.ApiContext apiContext, Entities.EntityObject entity) { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity); System.Data.Metadata.Edm.ItemCollection colleciton = null; if (context.MetadataWorkspace.TryGetItemCollection(System.Data.Metadata.Edm.DataSpace.CSpace, out colleciton)) { System.String typeFullName = entity.GetType().ToString(); Edm.EntityType entiyType = colleciton.GetItems <Edm.EntityType>() .Where(e => e.FullName.Equals(typeFullName, System.StringComparison.InvariantCultureIgnoreCase)) .First(); // SET all properties modified except those who are in ignore list foreach (Edm.EdmProperty property in entiyType.Properties) { if (!IsInIgnoreList(property.Name)) { ose.SetModifiedProperty(property.Name); } } } }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { CelulaLider entidad = (CelulaLider)entry.Entity; validarLiderzagoDeMiembro(entidad); }
partial void OnBorrar(System.Data.Objects.ObjectStateEntry entry) { SesionActual.Instance.ValidarPermisoEspecial((int)PermisosEspeciales.BorrarBoletasDeConsolidacion); }
partial void OnAgregar(System.Data.Objects.ObjectStateEntry entry) { SesionActual.Instance.ValidarPermisoEspecial((int)PermisosEspeciales.CrearBoletasDeConsolidacion); validarEntidad(entry); }
/// <summary> /// No Metadata Documentation available. /// </summary> /// <param name="apiContext"></param> /// <param name="imageTypes"></param> /// <param name="columnExpression"></param> /// <returns></returns> public static Helpers.ActionResult PartialUpdate(Helpers.ApiContext apiContext, System.Collections.Generic.IEnumerable <Entities.ImageType> imageTypes, params System.Linq.Expressions.Expression <System.Func <Entities.ImageType, object> >[] columnExpression) { // API doesn't allow null parameters. This method requires at least 1 item in the collection. if (apiContext == null) { throw new System.ArgumentNullException("apiContext"); } if (imageTypes == null) { throw new System.ArgumentNullException("imageTypes"); } if (imageTypes.Count() == 0) { throw new System.ArgumentOutOfRangeException("imageTypes"); } if (columnExpression == null) { throw new System.ArgumentNullException("columnExpression"); } if (columnExpression.Count() == 0) { throw new System.ArgumentOutOfRangeException("columnExpression"); } ValidateColumnExpression <Entities.ImageType>(columnExpression); Helpers.ActionResult result = Helpers.ActionResult.Factory(true); try { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; foreach (Entities.ImageType imageType in imageTypes) { // ATTACH object AttachObject(apiContext, "ImageTypes", imageType); // SET system level properties SetSystemProperties(apiContext, imageType); SetSystemPropertiesModified(apiContext, imageType); // SET IsActive property modified System.Data.Objects.ObjectStateEntry ose = apiContext.CurrentContext.ObjectStateManager.GetObjectStateEntry(imageType); foreach (var item in columnExpression) { ose.SetModifiedProperty(item.GetPropertyName()); } } context.SaveChanges(); // Save Changes DetachObjects(apiContext, imageTypes); // Clean ObjectState cache } catch (System.Data.OptimisticConcurrencyException ex) { object forDebugging = ex; HandleOptimisticConcurrencyException(apiContext, imageTypes, ex, ref result); } catch (System.Exception ex) { object forDebugging = ex; throw; // Helpers.Exceptions.UpdateEntityException.Factory(ex); } return(result); }
partial void OnBorrar(System.Data.Objects.ObjectStateEntry entry) { SesionActual.Instance.ValidarPermisoEspecial((int)PermisosEspeciales.BorrarCelulas); }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { FoliGrupo entidad = (FoliGrupo)entry.Entity; validarFechas(entidad); }
partial void OnBorrar(System.Data.Objects.ObjectStateEntry entry) { }
/// <summary> /// ApplyOriginalValues for Concurrency check in Update and Delete /// </summary> /// <param name="apiContext"></param> /// <param name="entity"></param> protected static void ApplyOriginalValues(Helpers.ApiContext apiContext, Entities.EntityObject entity) { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity); ose.ApplyOriginalValues(entity); }
private IEnumerable <History> Changeset(System.Data.Objects.ObjectStateEntry item) { var changedFields = (from p in item.GetModifiedProperties() let o = item.OriginalValues[p] let c = item.CurrentValues[p] where !object.Equals(o, c) select new { p = p, o = o == DBNull.Value ? null : o, c = c == DBNull.Value ? null : c, }).ToList(); var entity = (Daf)item.Entity; foreach (var change in changedFields) { switch (change.p) { case "StatusId": yield return(getHistoryBase(entity, global::Resources.Resource.DafStatus, ((Daf.Statuses)(int) change.o), ((Daf.Statuses)(int) change.c))); break; case "EvaluatorId": yield return(getHistoryBase(entity, global::Resources.Resource.Evaluator, db.Users.Where(f => f.Id == (int)change.o).Select(f => f.FirstName + " " + f.LastName).FirstOrDefault(), db.Users.Where(f => f.Id == (int)change.c).Select(f => f.FirstName + " " + f.LastName).FirstOrDefault())); break; case "AssessmentDate": yield return(getHistoryBase(entity, global::Resources.Resource.AssessmentDate, change.o, change.c)); break; case "EffectiveDate": yield return(getHistoryBase(entity, global::Resources.Resource.EffectiveDate, change.o, change.c)); break; case "GovernmentHours": yield return(getHistoryBase(entity, global::Resources.Resource.GovernmentHours, change.o, change.c)); break; case "ExceptionalHours": yield return(getHistoryBase(entity, global::Resources.Resource.ExceptionalHours, change.o, change.c)); break; case "Xml": foreach (var h in GetQuestionsHistory(entity, change.o, change.c)) { yield return(h); } break; case "TotalScore": yield return(getHistoryBase(entity, global::Resources.Resource.TotalScore, change.o, change.c)); break; case "FileName": yield return(getHistoryBase(entity, global::Resources.Resource.SignedDafUpload, change.o, change.c)); break; } } }
partial void OnModificar(System.Data.Objects.ObjectStateEntry entry) { SesionActual.Instance.ValidarPermisoEspecial((int)PermisosEspeciales.ModificarCelulas); validarEntidad(entry); }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { CelulaMiembroAsistencia entidad = (CelulaMiembroAsistencia)entry.Entity; cerrarBoleta(entidad); }
partial void OnModificar(System.Data.Objects.ObjectStateEntry entry) { validarEntidad(entry); }
private void validarEntidad(System.Data.Objects.ObjectStateEntry entry) { AlabanzaEvento entidad = (AlabanzaEvento)entry.Entity; validarHoras(entidad); }