| | 1 | | #if FAKE_XRM_EASY_2013 || FAKE_XRM_EASY_2015 || FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9 |
| | 2 | | using System; |
| | 3 | | using System.Linq; |
| | 4 | | using Microsoft.Xrm.Sdk; |
| | 5 | | using System.ServiceModel; |
| | 6 | | using Microsoft.Crm.Sdk.Messages; |
| | 7 | |
|
| | 8 | | namespace FakeXrmEasy.FakeMessageExecutors |
| | 9 | | { |
| | 10 | | public class RemoveUserFromRecordTeamRequestExecutor : IFakeMessageExecutor |
| | 11 | | { |
| | 12 | | public bool CanExecute(OrganizationRequest request) |
| 5 | 13 | | { |
| 5 | 14 | | return request is RemoveUserFromRecordTeamRequest; |
| 5 | 15 | | } |
| | 16 | |
|
| | 17 | | public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) |
| 5 | 18 | | { |
| 5 | 19 | | RemoveUserFromRecordTeamRequest remReq = (RemoveUserFromRecordTeamRequest)request; |
| | 20 | |
|
| 5 | 21 | | EntityReference target = remReq.Record; |
| 5 | 22 | | Guid systemuserId = remReq.SystemUserId; |
| 5 | 23 | | Guid teamTemplateId = remReq.TeamTemplateId; |
| | 24 | |
|
| 5 | 25 | | if (target == null) |
| 0 | 26 | | { |
| 0 | 27 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not remove from |
| | 28 | | } |
| | 29 | |
|
| 5 | 30 | | if (systemuserId == Guid.Empty) |
| 0 | 31 | | { |
| 0 | 32 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not remove from |
| | 33 | | } |
| | 34 | |
|
| 5 | 35 | | if (teamTemplateId == Guid.Empty) |
| 0 | 36 | | { |
| 0 | 37 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not remove from |
| | 38 | | } |
| | 39 | |
|
| 5 | 40 | | Entity teamTemplate = ctx.CreateQuery("teamtemplate").FirstOrDefault(p => p.Id == teamTemplateId); |
| 5 | 41 | | if (teamTemplate == null) |
| 0 | 42 | | { |
| 0 | 43 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Team template with i |
| | 44 | | } |
| | 45 | |
|
| 5 | 46 | | Entity user = ctx.CreateQuery("systemuser").FirstOrDefault(p => p.Id == systemuserId); |
| 5 | 47 | | if (user == null) |
| 0 | 48 | | { |
| 0 | 49 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "User with id=" + tea |
| | 50 | | } |
| | 51 | |
|
| 5 | 52 | | IOrganizationService service = ctx.GetOrganizationService(); |
| | 53 | |
|
| 5 | 54 | | ctx.AccessRightsRepository.RevokeAccessTo(target, user.ToEntityReference()); |
| 5 | 55 | | Entity team = ctx.CreateQuery("team").FirstOrDefault(p => ((EntityReference)p["teamtemplateid"]).Id == teamT |
| 5 | 56 | | if (team == null) |
| 0 | 57 | | { |
| 0 | 58 | | return new RemoveUserFromRecordTeamResponse |
| 0 | 59 | | { |
| 0 | 60 | | ResponseName = "RemoveUserFromRecordTeam" |
| 0 | 61 | | }; |
| | 62 | | } |
| | 63 | |
|
| 5 | 64 | | Entity tm = ctx.CreateQuery("teammembership").FirstOrDefault(p => (Guid)p["teamid"] == team.Id); |
| 5 | 65 | | if (tm != null) |
| 5 | 66 | | { |
| 5 | 67 | | service.Delete(tm.LogicalName, tm.Id); |
| 5 | 68 | | } |
| | 69 | |
|
| 5 | 70 | | return new RemoveUserFromRecordTeamResponse |
| 5 | 71 | | { |
| 5 | 72 | | ResponseName = "RemoveUserFromRecordTeam" |
| 5 | 73 | | }; |
| 5 | 74 | | } |
| | 75 | |
|
| | 76 | | public Type GetResponsibleRequestType() |
| 3597 | 77 | | { |
| 3597 | 78 | | return typeof(RemoveUserFromRecordTeamRequestExecutor); |
| 3597 | 79 | | } |
| | 80 | | } |
| | 81 | | } |
| | 82 | | #endif |