public void When_Deleting_Using_Organization_Context_Record_Should_Be_Deleted() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)); var account = new Account() { Id = Guid.NewGuid(), Name = "Super Great Customer", AccountNumber = "69" }; var service = context.GetFakedOrganizationService(); using (var ctx = new OrganizationServiceContext(service)) { ctx.AddObject(account); ctx.SaveChanges(); } Assert.NotNull(service.Retrieve(Account.EntityLogicalName, account.Id, new ColumnSet(true))); using (var ctx = new OrganizationServiceContext(service)) { ctx.Attach(account); ctx.DeleteObject(account); ctx.SaveChanges(); var retrievedAccount = ctx.CreateQuery <Account>().SingleOrDefault(acc => acc.Id == account.Id); Assert.Null(retrievedAccount); } }
public override void DeleteEntity(OrganizationServiceContext context, string entitySet, Guid entityID) { var entity = GetServiceOperationEntityByID(context, entitySet, entityID); AssertCrmEntityChangeAccess(context, entity); CrmEntityInactiveInfo inactiveInfo; if (CrmEntityInactiveInfo.TryGetInfo(entity.LogicalName, out inactiveInfo)) { context.SetState(inactiveInfo.InactiveState, inactiveInfo.InactiveStatus, entity); return; } if (entity.LogicalName == "adx_communityforum" || entity.LogicalName == "adx_event" || entity.LogicalName == "adx_shortcut") { context.DeleteObject(entity); context.SaveChanges(); return; } throw new DataServiceException(403, "This operation cannot be performed entities of type {0}.".FormatWith(entity.LogicalName)); }
public static void DeleteForumThread(this OrganizationServiceContext context, Entity thread) { thread.AssertEntityName("adx_communityforumthread"); context.DeleteObject(thread); context.SaveChanges(); }
public void Delete(T entity) { if (!service.IsAttached(entity)) { service.Attach(entity); } service.DeleteObject(entity); service.SaveChanges(SaveChangesOptions.None); }
public void RemoveItemFromCart(Guid itemID) { var item = _context.CreateQuery("adx_shoppingcartitem").FirstOrDefault(sci => sci.GetAttributeValue <Guid>("adx_shoppingcartitemid") == itemID); if (item != null) { _context.DeleteObject(item); _context.SaveChanges(); } }
public static void DeleteForumPost(this OrganizationServiceContext context, Entity post) { post.AssertEntityName("adx_communityforumpost"); UpdateThreadOnPostDelete(context, post); context.ReAttach(post); context.DeleteObject(post); context.SaveChanges(); }
static void DeleteLinq(OrganizationServiceProxy serviceProxy) { OrganizationServiceContext context = new OrganizationServiceContext(serviceProxy); var resultados = from a in context.CreateQuery("account") where ((string)a["name"]) == "Teste" select a; foreach (var item in resultados) { context.DeleteObject(item); } context.SaveChanges(); }
public static void RemoveThreadAlertAndSave(this OrganizationServiceContext context, Entity thread, Entity contact) { thread.AssertEntityName("adx_communityforumthread"); contact.AssertEntityName("contact"); var forumAlerts = thread.GetRelatedEntities(context, "adx_communityforumthread_communityforumaalert"); var alert = ( from e in forumAlerts where e.GetAttributeValue <EntityReference>("adx_subscriberid") == contact.ToEntityReference() select e).FirstOrDefault(); if (alert != null) { context.DeleteObject(alert); } context.SaveChanges(); }
public void Delete <T>(T entity) where T : BaseEntity { context.DeleteObject(entity); }
protected override void ProcessRequest(HttpContext context, ICmsEntityServiceProvider serviceProvider, Guid portalScopeId, IPortalContext portal, OrganizationServiceContext serviceContext, Entity entity, CmsEntityMetadata entityMetadata, ICrmEntitySecurityProvider security) { if (!(IsRequestMethod(context.Request, "POST") || IsRequestMethod(context.Request, "DELETE"))) { throw new CmsEntityServiceException(HttpStatusCode.MethodNotAllowed, "Request method {0} not allowed for this resource.".FormatWith(context.Request.HttpMethod)); } CrmEntityInactiveInfo inactiveInfo; if (CrmEntityInactiveInfo.TryGetInfo(entity.LogicalName, out inactiveInfo)) { serviceContext.SetState(inactiveInfo.InactiveState, inactiveInfo.InactiveStatus, entity); WriteNoContentResponse(context.Response); return; } if (entity.LogicalName == "adx_communityforumthread") { var forum = entity.GetRelatedEntity(serviceContext, new Relationship("adx_communityforum_communityforumthread")); if (forum != null) { var forumDataAdapter = new ForumDataAdapter( forum.ToEntityReference(), new PortalConfigurationDataAdapterDependencies(portalName: PortalName, requestContext: context.Request.RequestContext)); forumDataAdapter.DeleteThread(entity.ToEntityReference()); WriteNoContentResponse(context.Response); if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage)) { PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Forum, HttpContext.Current, "delete_forumthread", 1, entity.ToEntityReference(), "delete"); } return; } } if (entity.LogicalName == "adx_communityforumpost") { var forumThread = entity.GetRelatedEntity(serviceContext, new Relationship("adx_communityforumthread_communityforumpost")); if (forumThread != null) { var forumThreadDataAdapter = new ForumThreadDataAdapter( forumThread.ToEntityReference(), new PortalConfigurationDataAdapterDependencies(portalName: PortalName, requestContext: context.Request.RequestContext)); forumThreadDataAdapter.DeletePost(entity.ToEntityReference()); WriteNoContentResponse(context.Response); if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage)) { PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Forum, HttpContext.Current, "delete_forumpost", 1, entity.ToEntityReference(), "delete"); } return; } } serviceContext.DeleteObject(entity); serviceContext.SaveChanges(); WriteNoContentResponse(context.Response); if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage)) { PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Blog, HttpContext.Current, "delete_blogpost", 1, entity.ToEntityReference(), "delete"); } }
public void When_Deleting_Using_Organization_Context_Record_Should_Be_Deleted() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)); var account = new Account() { Id = Guid.NewGuid(), Name = "Super Great Customer", AccountNumber = "69" }; var service = context.GetFakedOrganizationService(); using (var ctx = new OrganizationServiceContext(service)) { ctx.AddObject(account); ctx.SaveChanges(); } Assert.NotNull(service.Retrieve(Account.EntityLogicalName, account.Id, new ColumnSet(true))); using (var ctx = new OrganizationServiceContext(service)) { ctx.Attach(account); ctx.DeleteObject(account); ctx.SaveChanges(); var retrievedAccount = ctx.CreateQuery<Account>().SingleOrDefault(acc => acc.Id == account.Id); Assert.Null(retrievedAccount); } }
public void CaseDeletion(IOrganizationService _orgServ) { Console.WriteLine("Starting Case Deletion"); OrganizationServiceContext _orgContext = new OrganizationServiceContext(_orgServ); Incident myCase = null; int pageNo = 1; int record = 0; string casTickNum = ""; string casType; Guid last = new Guid(); Guid first = new Guid(); start: EntityCollection retrievedCases = GetCases(_orgServ, pageNo, casTickNum, first, last); if (retrievedCases.Entities.Count > 1) { Console.WriteLine("Cases Retrieved"); for (int r = 0; r < retrievedCases.Entities.Count; r++) { record++; Console.WriteLine("record number = " + record); myCase = retrievedCases[r].ToEntity <Incident>(); var casId = myCase.IncidentId; if (myCase.gcs_CaseTypes == null) { _orgContext.Attach(myCase); _orgContext.DeleteObject(myCase); _orgContext.Dispose(); continue; } casType = myCase.gcs_CaseTypes.Name.ToString(); CaseSaveList((Guid)casId, casType); int idExist = safeList.FindIndex(s => s.caseGuid == casId); try { if (idExist >= 0) { Entity updateCase = new Entity(); updateCase.LogicalName = myCase.LogicalName; updateCase.Attributes["shg_casesavefield"] = true; updateCase.Id = myCase.Id; if (myCase.StateCode != 0) { SetStateRequest setStateRequest = new SetStateRequest() { EntityMoniker = new EntityReference { Id = myCase.Id, LogicalName = myCase.LogicalName, }, Status = new OptionSetValue(1), State = new OptionSetValue(0) }; _orgServ.Execute(setStateRequest); } _orgServ.Update(updateCase); continue; } } catch (FaultException <OrganizationServiceFault> e) { Console.WriteLine(e + "case which failed = " + myCase.TicketNumber + " case type = " + myCase.gcs_CaseTypes); continue; } } pageNo++; first = (Guid)retrievedCases.Entities.Select(s => s.Attributes["incidentid"]).First(); last = (Guid)retrievedCases.Entities.Select(s => s.Attributes["incidentid"]).Last(); goto start; } else { BulkCaseDeletion(_orgServ); BulkActivityDeletion(_orgServ); } }