private SetStateResponse ExecuteInternal(SetStateRequest request) { var entity = Service.Retrieve(request.EntityMoniker.LogicalName, request.EntityMoniker.Id, new ColumnSet()); var info = new LateBoundActivePropertyInfo(request.EntityMoniker.LogicalName); switch (info.ActiveAttribute) { case ActiveAttributeType.IsDisabled: entity["isdisabled"] = request.State.GetValueOrDefault() == 1; break; case ActiveAttributeType.None: case ActiveAttributeType.StateCode: entity["statecode"] = request.State; entity["statuscode"] = request.Status; break; default: throw new ArgumentOutOfRangeException(); } Service.Update(entity); return(new SetStateResponse()); }
/// <summary> /// Determines whether the specified entity is active. /// </summary> /// <param name="service">The service.</param> /// <param name="logicalName">Name of the logical.</param> /// <param name="entityId">The entity identifier.</param> /// <returns></returns> public static bool?IsActive(IOrganizationService service, string logicalName, Guid entityId) { var info = new LateBoundActivePropertyInfo(logicalName); var entity = service.Retrieve(logicalName, entityId, new ColumnSet(info.AttributeName)); return(IsActive(info, entity)); }
/// <summary> /// Currently only tested against System Users. Not sure if it will work with other entities /// May need to rename this to SetSystemUserState /// </summary> /// <param name="service">The service.</param> /// <param name="entity">The entity.</param> /// <param name="active">if set to <c>true</c> [active].</param> /// <returns></returns> public static void SetState(this IOrganizationService service, EntityReference entity, bool active) { var info = new LateBoundActivePropertyInfo(entity.LogicalName); var state = active ? info.ActiveState ?? 0 : info.NotActiveState ?? (info.ActiveState == 1 ? 0 : 1); SetState(service, entity, state); }
/// <summary> /// Sets the state /// </summary> /// <param name="service">The service.</param> /// <param name="entity">The entity to set the state of.</param> /// <param name="state">The state to change the entity to.</param> /// <param name="status">The status to change the entity to.</param> /// <returns></returns> public static void SetState(this IOrganizationService service, EntityReference entity, int state, int?status = null) { var info = new LateBoundActivePropertyInfo(entity.LogicalName); var local = new Entity(entity.LogicalName) { Id = entity.Id, [info.AttributeName] = info.ActiveAttribute == ActiveAttributeType.IsDisabled ? (object)(state == 1) : new OptionSetValue(state) }; if (status.HasValue) { local["status"] = new OptionSetValue(status.Value); } service.Update(local); }
public static void IsNotActive <T>(IOrganizationService service, Id <T> id, string message = null, params object[] parameters) where T : Entity { if (typeof(T) == typeof(Entity)) { // Late Bound var isActive = LateBoundActivePropertyInfo.IsActive(service, id.Entity); if (isActive == null) { HandleInconclusive("AssertCrm.IsNotActive", "Unable to determine Status of Entity Type {0}", typeof(T).Name); } else if (isActive == true) { HandleFail("AssertCrm.IsActive", message, parameters); } } else { // Early Bound IsNotActive <T>(service, id.EntityId, message, parameters); } }
private SetStateResponse ExecuteInternal(SetStateRequest request) { var entity = Service.Retrieve(request.EntityMoniker.LogicalName, request.EntityMoniker.Id, new ColumnSet()); var info = new LateBoundActivePropertyInfo(request.EntityMoniker.LogicalName); switch (info.ActiveAttribute) { case ActiveAttributeType.IsDisabled: entity["isdisabled"] = request.State.GetValueOrDefault() == 1; break; case ActiveAttributeType.None: case ActiveAttributeType.StateCode: entity["statecode"] = request.State; entity["statuscode"] = request.Status; break; default: throw new ArgumentOutOfRangeException(); } Service.Update(entity); return new SetStateResponse(); }