Пример #1
0
        public void CanGetUserGroups()
        {
            var key           = "GroupMember_CanGetUserGroups";
            var acceptorNames = new[] {
                key + "_Group1",
                key + "_Group2",
                key + "_Group3",
                key + "_Group4",
                key + "_Group5"
            };

            foreach (var name in acceptorNames)
            {
                var group = CreateGroup(name);
                var loggedInAccountLoop = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);
                var relationshipRequest = new RelationshipRequest
                {
                    RequestorId = loggedInAccountLoop.User.Id,
                    AcceptorId  = group.Id,
                    AutoAccept  = true
                };
                Fixture.SUGARClient.GroupMember.CreateMemberRequest(relationshipRequest);
            }

            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var userGroups = Fixture.SUGARClient.GroupMember.GetUserGroups(loggedInAccount.User.Id);

            Assert.Equal(5, userGroups.Count());

            var groupCheck = userGroups.Where(r => acceptorNames.Any(an => r.Name.Contains(an)));

            Assert.Equal(5, groupCheck.Count());
        }
Пример #2
0
        public void RelationshipChainedSave()
        {
            using (var client = TestHelper.ClientGet())
            {
                DateTime today = DateTime.Today;

                // Fire all contacts working for the company.
                var request = new RelationshipRequest
                {
                    RelationshipTypeId      = 5, // Works for
                    ContactIdB              = _myCompanyId,
                    IsActive                = true,
                    RelationshipSaveRequest = new[]
                    {
                        new RelationshipRequest
                        {
                            IdValueExpression = "$value.id",
                            IsActive          = false,
                            EndDate           = today
                        }
                    }
                };
                // Get relationship to see if it worked.
                var result       = client.RelationshipGet(TestHelper.ApiKey, TestHelper.SiteKey, request);
                var relationship = client.RelationshipGetSingle(TestHelper.ApiKey, TestHelper.SiteKey,
                                                                new RelationshipRequest {
                    Id = _myRelationshipId
                });
                Assert.IsFalse(relationship.IsActive);
                Assert.AreEqual(today, relationship.EndDate);
            }
        }
Пример #3
0
        public void CannotUpdateAlreadyAcceptedRequest()
        {
            var key             = "GroupMember_CannotUpdateAlreadyAcceptedRequest";
            var group           = CreateGroup(key);
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = group.Id,
                AutoAccept  = true
            };

            Fixture.SUGARClient.GroupMember.CreateMemberRequest(relationshipRequest);

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key + "_Creator");

            var relationshipStatusUpdate = new RelationshipStatusUpdate
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = group.Id,
                Accepted    = true
            };

            Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.GroupMember.UpdateMemberRequest(relationshipStatusUpdate));
        }
Пример #4
0
        public void CanCreateAutoAcceptedRequest()
        {
            var key             = "UserFriend_CanCreateAutoAcceptedRequest";
            var friend          = CreateUser(key);
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = friend.Id,
                AutoAccept  = true
            };

            var relationshipResponse = Fixture.SUGARClient.UserFriend.CreateFriendRequest(relationshipRequest);

            Assert.Equal(relationshipRequest.RequestorId, relationshipResponse.RequestorId);
            Assert.Equal(relationshipRequest.AcceptorId, relationshipResponse.AcceptorId);

            var sent = Fixture.SUGARClient.UserFriend.GetFriends(loggedInAccount.User.Id);

            Assert.Equal(1, sent.Count());

            var received = Fixture.SUGARClient.UserFriend.GetFriends(friend.Id);

            Assert.Equal(1, received.Count());
        }
Пример #5
0
        public void CanCreateAutoAcceptedRequest()
        {
            var key             = "GroupMember_CanCreateAutoAcceptedRequest";
            var group           = CreateGroup(key);
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = group.Id,
                AutoAccept  = true
            };

            var relationshipResponse = Fixture.SUGARClient.GroupMember.CreateMemberRequest(relationshipRequest);

            Assert.Equal(relationshipRequest.RequestorId, relationshipResponse.RequestorId);
            Assert.Equal(relationshipRequest.AcceptorId, relationshipResponse.AcceptorId);

            var sent = Fixture.SUGARClient.GroupMember.GetUserGroups(loggedInAccount.User.Id);

            Assert.Equal(1, sent.Count());

            var received = Fixture.SUGARClient.GroupMember.GetMembers(group.Id);

            Assert.Equal(2, received.Count());

            var receivedCount = Fixture.SUGARClient.GroupMember.GetMemberCount(group.Id);

            Assert.Equal(2, receivedCount);
        }
Пример #6
0
        public void CanJoinGroupAndTakeResources()
        {
            var key             = "GroupMember_CanJoinGroupAndTakeResources";
            var group           = CreateGroup(key);
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = group.Id,
                AutoAccept  = true
            };

            var relationshipResponse = Fixture.SUGARClient.GroupMember.CreateMemberRequest(relationshipRequest);

            Assert.Equal(relationshipRequest.RequestorId, relationshipResponse.RequestorId);
            Assert.Equal(relationshipRequest.AcceptorId, relationshipResponse.AcceptorId);

            var initialQunatity  = 100;
            var transferQuantity = 20;

            var resourceResponse = GiveResource(Platform.GlobalGameId, group.Id, key, initialQunatity);

            Assert.Equal(resourceResponse.Quantity, initialQunatity);

            // Act
            var transferResponse = TakeResource(Platform.GlobalGameId, key, loggedInAccount.User.Id, group.Id, transferQuantity);

            Assert.Equal(initialQunatity - transferQuantity, transferResponse.FromResource.Quantity);
            Assert.Equal(transferQuantity, transferResponse.ToResource.Quantity);
        }
        public void CannotUpdateAlreadyAcceptedRequest()
        {
            var key = "Alliance_CannotUpdateAlreadyAcceptedRequest";

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);
            var group1 = CreateGroup(key + "_Req");
            var group2 = CreateGroup(key + "_Acc");

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = group1.Id,
                AcceptorId  = group2.Id,
                AutoAccept  = true
            };

            Fixture.SUGARClient.AllianceClient.CreateAllianceRequest(relationshipRequest);

            var relationshipStatusUpdate = new RelationshipStatusUpdate
            {
                RequestorId = group1.Id,
                AcceptorId  = group2.Id,
                Accepted    = true
            };

            Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.AllianceClient.UpdateAllianceRequest(relationshipStatusUpdate));
        }
Пример #8
0
        public void CanGetUserfriends()
        {
            var key           = "UserFriend_CanGetUserfriends";
            var acceptorNames = new[] {
                key + "1",
                key + "2",
                key + "3",
                key + "4",
                key + "5"
            };

            foreach (var name in acceptorNames)
            {
                var friend = CreateUser(name);
                var loggedInAccountLoop = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);
                var relationshipRequest = new RelationshipRequest
                {
                    RequestorId = loggedInAccountLoop.User.Id,
                    AcceptorId  = friend.Id,
                    AutoAccept  = true
                };
                Fixture.SUGARClient.UserFriend.CreateFriendRequest(relationshipRequest);
            }

            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var userfriends = Fixture.SUGARClient.UserFriend.GetFriends(loggedInAccount.User.Id);

            Assert.Equal(5, userfriends.Count());

            var friendCheck = userfriends.Where(r => acceptorNames.Any(an => r.Name.Contains(an)));

            Assert.Equal(5, friendCheck.Count());
        }
Пример #9
0
        /// <summary>
        /// 添加操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public JsonResponse AddRelationship(RelationshipRequest request)
        {
            if (request?.EnterpriseID == Guid.Empty || request?.UserId == Guid.Empty)
            {
                return(new JsonResponse(OperatingState.CheckDataFail, "未传入必要的条件"));
            }

            if (_relationship.Table.Any(c => c.EnterpriseID == request.EnterpriseID && c.UserId == request.UserId && c.DeletedState != (int)DeletedStates.Deleted))
            {
                return(new JsonResponse(OperatingState.CheckDataFail, "已经存在该企业和用户"));
            }
            var obj = new Relationship()
            {
                Id           = Guid.NewGuid(),
                UserId       = request.UserId,
                EnterpriseID = request.EnterpriseID,
                RoleId       = request.RoleId,
                DeptInfoId   = request.DeptInfoId,
                State        = request.State,
                IsEnterprise = request.IsEnterprise,
                CreateTime   = DateTime.Now
            };

            try
            {
                _relationship.Insert(obj);
                _relationship.SaveChanges();
                return(new JsonResponse(OperatingState.Success, "添加成功"));
            }
            catch (Exception e)
            {
                return(new JsonResponse(OperatingState.Success, "操作时出现异常 " + e.Message));
            }
        }
 internal static void Add(int id, Action <bool> onComplete, bool autoAccept = true)
 {
     SUGARManager.unity.StartSpinner();
     if (SUGARManager.UserSignedIn)
     {
         var relationship = new RelationshipRequest
         {
             RequestorId = SUGARManager.CurrentUser.Id,
             AcceptorId  = id,
             AutoAccept  = autoAccept
         };
         SUGARManager.client.UserFriend.CreateFriendRequestAsync(relationship,
                                                                 response =>
         {
             SUGARManager.userFriend.RefreshRelationships(onComplete);
         },
                                                                 exception =>
         {
             Debug.LogError($"Failed to create friend request. {exception}");
             SUGARManager.unity.StopSpinner();
             onComplete(false);
         });
     }
     else
     {
         SUGARManager.unity.StopSpinner();
         onComplete(false);
     }
 }
        public async Task <IActionResult> Create([FromBody] RelationshipRequest request)
        {
            try
            {
                var relationship = await _relationshipApp.Create(request);

                var notification = new Notification()
                {
                    CreatedAt = DateTime.Now,
                    FromId    = request.FromId,
                    ToId      = request.ToId,
                    Type      = "relationship"
                };

                var notificationResponse = await _notificationApp.CreateNotification(notification);

                try
                {
                    await _notificationApp.SendNotification(notificationResponse);
                }
                catch (Exception)
                {
                }
                return(Ok(relationship));
            }
            catch (Exception e)
            {
                return(BadRequest(new
                {
                    Message = e.Message
                }));
            }
        }
Пример #12
0
        public void CannotUpdateAlreadyAcceptedRequest()
        {
            var key             = "UserFriend_CannotUpdateAlreadyAcceptedRequest";
            var friend          = CreateUser(key);
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = friend.Id,
                AutoAccept  = true
            };

            Fixture.SUGARClient.UserFriend.CreateFriendRequest(relationshipRequest);

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key + "_Friend");

            var relationshipStatusUpdate = new RelationshipStatusUpdate
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = friend.Id,
                Accepted    = true
            };

            Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.UserFriend.UpdateFriendRequest(relationshipStatusUpdate));
        }
        public void CanGetAlliances()
        {
            var key = "Alliance_CanGetAlliances";

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);
            var group2 = CreateGroup(key + "_Acc");

            var requestorNames = new[] {
                key + "1",
                key + "2",
                key + "3",
                key + "4",
                key + "5"
            };

            foreach (var name in requestorNames)
            {
                var group = CreateGroup(name);
                var relationshipRequest = new RelationshipRequest
                {
                    RequestorId = group.Id,
                    AcceptorId  = group2.Id,
                    AutoAccept  = true
                };
                Fixture.SUGARClient.AllianceClient.CreateAllianceRequest(relationshipRequest);
            }

            var alliances = Fixture.SUGARClient.AllianceClient.GetAlliances(group2.Id);

            Assert.Equal(5, alliances.Count());

            var allianceCheck = alliances.Where(r => requestorNames.Any(rn => r.Name.Contains(rn)));

            Assert.Equal(5, allianceCheck.Count());
        }
        public void CanCreateAutoAcceptedRequest()
        {
            var key = "Alliance_CanCreateAutoAcceptedRequest";

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);
            var group1 = CreateGroup(key + "_Req");
            var group2 = CreateGroup(key + "_Acc");

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = group1.Id,
                AcceptorId  = group2.Id,
                AutoAccept  = true
            };

            var relationshipResponse = Fixture.SUGARClient.AllianceClient.CreateAllianceRequest(relationshipRequest);

            Assert.Equal(relationshipRequest.RequestorId, relationshipResponse.RequestorId);
            Assert.Equal(relationshipRequest.AcceptorId, relationshipResponse.AcceptorId);

            var sent = Fixture.SUGARClient.AllianceClient.GetAlliances(group1.Id);

            Assert.Equal(1, sent.Count());

            var received = Fixture.SUGARClient.AllianceClient.GetAlliances(group2.Id);

            Assert.Equal(1, received.Count());
        }
Пример #15
0
        public void RelationshipChainedGetDelete()
        {
            using (var client = TestHelper.ClientGet())
            {
                var request = new RelationshipRequest
                {
                    ContactIdB                = _myCompanyId,
                    EndDateFilter             = new Filter <DateTime?>(WhereOperator.Gt, new DateTime(2016, 8, 7)),
                    RelationshipDeleteRequest = new List <DeleteRequest> {
                        new DeleteRequest {
                            IdValueExpression = "$value.id"
                        }
                    }
                };

                // Find and remove relationship.
                var result = client.RelationshipGet(TestHelper.ApiKey, TestHelper.SiteKey, request);

                var result2 = client.RelationshipGet(TestHelper.ApiKey, TestHelper.SiteKey,
                                                     new RelationshipRequest {
                    Id = _myOtherRelationshipId
                });

                Assert.AreEqual(0, result2.Count);
            }
        }
Пример #16
0
        public void NewRelationship()
        {
            using (var client = TestHelper.ClientGet())
            {
                var relationshipRequest = new RelationshipRequest
                {
                    RelationshipTypeId = 5, // Works for
                    ContactIdA         = _myContactId,
                    ContactIdB         = 1, // Default organization
                    StartDate          = DateTime.Now.Date,
                    EndDate            = DateTime.Now.Date.AddYears(1),
                    IsActive           = true
                };

                var result          = client.RelationshipSave(TestHelper.ApiKey, TestHelper.SiteKey, relationshipRequest);
                var newRelationship = result.Values.First();

                Assert.AreEqual(relationshipRequest.ContactIdA, newRelationship.ContactIdA);
                Assert.AreEqual(relationshipRequest.ContactIdB, newRelationship.ContactIdB);
                Assert.AreEqual(relationshipRequest.StartDate, newRelationship.StartDate);
                Assert.AreEqual(relationshipRequest.EndDate, newRelationship.EndDate);
                Assert.AreEqual(relationshipRequest.IsActive, newRelationship.IsActive);
                Assert.AreEqual(relationshipRequest.RelationshipTypeId, newRelationship.RelationshipTypeId);
            }
        }
 public static ActorRelationship ToRelationshipModel(this RelationshipRequest relationContract)
 {
     return(new ActorRelationship
     {
         RequestorId = relationContract.RequestorId.Value,
         AcceptorId = relationContract.AcceptorId.Value
     });
 }
Пример #18
0
        public void CanRejectRequest()
        {
            var key             = "GroupMember_CanRejectRequest";
            var group           = CreateGroup(key);
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = group.Id,
                AutoAccept  = false
            };

            Fixture.SUGARClient.GroupMember.CreateMemberRequest(relationshipRequest);

            var sent = Fixture.SUGARClient.GroupMember.GetSentRequests(loggedInAccount.User.Id);

            Assert.Equal(1, sent.Count());

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key + "_Creator");

            var received = Fixture.SUGARClient.GroupMember.GetMemberRequests(group.Id);

            Assert.Equal(1, received.Count());

            var relationshipStatusUpdate = new RelationshipStatusUpdate
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = group.Id,
                Accepted    = false
            };

            Fixture.SUGARClient.GroupMember.UpdateMemberRequest(relationshipStatusUpdate);

            received = Fixture.SUGARClient.GroupMember.GetMemberRequests(group.Id);

            Assert.Equal(0, received.Count());

            received = Fixture.SUGARClient.GroupMember.GetMembers(group.Id);

            Assert.Equal(1, received.Count());

            var receivedCount = Fixture.SUGARClient.GroupMember.GetMemberCount(group.Id);

            Assert.Equal(1, receivedCount);

            loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            sent = Fixture.SUGARClient.GroupMember.GetSentRequests(loggedInAccount.User.Id);

            Assert.Equal(0, sent.Count());

            sent = Fixture.SUGARClient.GroupMember.GetUserGroups(loggedInAccount.User.Id);

            Assert.Equal(0, sent.Count());
        }
 public async Task <IActionResult> CreateAllianceRequest([FromBody] RelationshipRequest relationship)
 {
     if ((await _authorizationService.AuthorizeAsync(User, relationship.RequestorId, HttpContext.ScopeItems(ClaimScope.Group))).Succeeded ||
         (await _authorizationService.AuthorizeAsync(User, relationship.AcceptorId, HttpContext.ScopeItems(ClaimScope.Group))).Succeeded)
     {
         var request = relationship.ToRelationshipModel();
         _relationshipCoreController.CreateRequest(relationship.ToRelationshipModel(), relationship.AutoAccept);
         var relationshipContract = request.ToContract();
         return(new ObjectResult(relationshipContract));
     }
     return(Forbid());
 }
Пример #20
0
        public void CanRejectRequest()
        {
            var key             = "UserFriend_CanRejectRequest";
            var friend          = CreateUser(key);
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = friend.Id,
                AutoAccept  = false
            };

            Fixture.SUGARClient.UserFriend.CreateFriendRequest(relationshipRequest);

            var sent = Fixture.SUGARClient.UserFriend.GetSentRequests(loggedInAccount.User.Id);

            Assert.Equal(1, sent.Count());

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key + "_Friend");

            var received = Fixture.SUGARClient.UserFriend.GetFriendRequests(friend.Id);

            Assert.Equal(1, received.Count());

            var relationshipStatusUpdate = new RelationshipStatusUpdate
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = friend.Id,
                Accepted    = false
            };

            Fixture.SUGARClient.UserFriend.UpdateFriendRequest(relationshipStatusUpdate);

            received = Fixture.SUGARClient.UserFriend.GetFriendRequests(friend.Id);

            Assert.Equal(0, received.Count());

            received = Fixture.SUGARClient.UserFriend.GetFriends(friend.Id);

            Assert.Equal(0, received.Count());

            loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            sent = Fixture.SUGARClient.UserFriend.GetSentRequests(loggedInAccount.User.Id);

            Assert.Equal(0, sent.Count());

            sent = Fixture.SUGARClient.UserFriend.GetFriends(loggedInAccount.User.Id);

            Assert.Equal(0, sent.Count());
        }
Пример #21
0
        public void CannotCreateRequestWithNonExistingFriend()
        {
            var key             = "UserFriend_CannotCreateRequestWithNonExistingFriend";
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = -1
            };

            Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.UserFriend.CreateFriendRequest(relationshipRequest));
        }
        public void CanRejectRequest()
        {
            var key = "Alliance_CanRejectRequest";

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);
            var group1 = CreateGroup(key + "_Req");
            var group2 = CreateGroup(key + "_Acc");

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = group1.Id,
                AcceptorId  = group2.Id,
                AutoAccept  = false
            };

            Fixture.SUGARClient.AllianceClient.CreateAllianceRequest(relationshipRequest);

            var sent = Fixture.SUGARClient.AllianceClient.GetSentRequests(group1.Id);

            Assert.Equal(1, sent.Count());

            var received = Fixture.SUGARClient.AllianceClient.GetAllianceRequests(group2.Id);

            Assert.Equal(1, received.Count());

            var relationshipStatusUpdate = new RelationshipStatusUpdate
            {
                RequestorId = group1.Id,
                AcceptorId  = group2.Id,
                Accepted    = false
            };

            Fixture.SUGARClient.AllianceClient.UpdateAllianceRequest(relationshipStatusUpdate);

            received = Fixture.SUGARClient.AllianceClient.GetAllianceRequests(group2.Id);

            Assert.Equal(0, received.Count());

            received = Fixture.SUGARClient.AllianceClient.GetAlliances(group2.Id);

            Assert.Equal(0, received.Count());

            sent = Fixture.SUGARClient.AllianceClient.GetSentRequests(group1.Id);

            Assert.Equal(0, sent.Count());

            sent = Fixture.SUGARClient.AllianceClient.GetAlliances(group1.Id);

            Assert.Equal(0, sent.Count());
        }
Пример #23
0
        public void CannotCreateRequestWithNonExistingUser()
        {
            var key    = "UserFriend_CannotCreateRequestWithNonExistingUser";
            var friend = CreateUser(key);

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = -1,
                AcceptorId  = friend.Id
            };

            Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.UserFriend.CreateFriendRequest(relationshipRequest));
        }
Пример #24
0
        public void CannotCreateRequestWithNonExistingUser()
        {
            var key   = "GroupMember_CannotCreateRequestWithNonExistingUser";
            var group = CreateGroup(key);

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = -1,
                AcceptorId  = group.Id
            };

            Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.GroupMember.CreateMemberRequest(relationshipRequest));
        }
        public void CannotCreateRequestWithNonExistingGroup()
        {
            var key = "Alliance_CannotCreateRequestWithNonExistingGroup";

            Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);
            var group2 = CreateGroup(key + "_Acc");

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = -1,
                AcceptorId  = group2.Id
            };

            Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.AllianceClient.CreateAllianceRequest(relationshipRequest));
        }
 public async Task <IActionResult> RemoveAlliance([FromBody] RelationshipStatusUpdate relationship)
 {
     if ((await _authorizationService.AuthorizeAsync(User, relationship.RequestorId, HttpContext.ScopeItems(ClaimScope.Group))).Succeeded ||
         (await _authorizationService.AuthorizeAsync(User, relationship.AcceptorId, HttpContext.ScopeItems(ClaimScope.Group))).Succeeded)
     {
         var relation = new RelationshipRequest
         {
             RequestorId = relationship.RequestorId,
             AcceptorId  = relationship.AcceptorId
         };
         _relationshipCoreController.Delete(relation.ToRelationshipModel());
         return(Ok());
     }
     return(Forbid());
 }
Пример #27
0
        public void RelationshipDateFilter2()
        {
            using (var client = TestHelper.ClientGet())
            {
                var request = new RelationshipRequest
                {
                    ContactIdB    = _myCompanyId,
                    EndDateFilter = new Filter <DateTime?>(WhereOperator.Lt, new DateTime(2016, 8, 7))
                };

                var result = client.RelationshipGet(TestHelper.ApiKey, TestHelper.SiteKey, request);

                Assert.AreEqual(0, result.Count);
            }
        }
        public void CreateWithChainedRelationship()
        {
            using (var client = TestHelper.ClientGet())
            {
                var relationshipSaveRequest = new RelationshipRequest
                {
                    RelationshipTypeId        = 5,
                    ContactIdB                = 1,
                    ContactIdAValueExpression = "$value.id"
                };

                var contact = new ContactRequest
                {
                    ContactType             = ContactType.Individual,
                    FirstName               = "Lucky",
                    LastName                = "Luke",
                    BirthDate               = new DateTime(1946, 3, 3),
                    Gender                  = Gender.Male,
                    ExternalIdentifier      = "test_ext_id_yep",
                    RelationshipSaveRequest = new[] { relationshipSaveRequest },
                    ApiOptions              = new ApiOptions {
                        Match = "external_identifier"
                    }
                };

                var saveResult = client.ContactSave(TestHelper.ApiKey, TestHelper.SiteKey, contact);
                var getResult  = client.ContactGetSingle(TestHelper.ApiKey, TestHelper.SiteKey,
                                                         new ContactRequest
                {
                    Id = saveResult.Id,
                    RelationshipGetRequest = new RelationshipRequest {
                        ContactIdAValueExpression = "$value.id"
                    }
                });

                // Delete first (cleanup), check afterward.
                client.ContactDelete(TestHelper.ApiKey, TestHelper.SiteKey, new DeleteRequest(saveResult.Id.Value), 1);

                Assert.AreEqual(0, saveResult.IsError);
                Assert.AreEqual(1, getResult.RelationshipResult.Count);

                var relationShip = getResult.RelationshipResult.Values.First();

                Assert.AreEqual(relationshipSaveRequest.RelationshipTypeId, relationShip.RelationshipTypeId);
                Assert.AreEqual(relationshipSaveRequest.ContactIdB, relationShip.ContactIdB);
            }
        }
Пример #29
0
        public string AddRelation(RelationshipRequest request)
        {
            if (request != null)
            {
                Relationship relationship = new Relationship();

                relationship.EmployeeId = request.EmployeeId;
                relationship.ProjectId  = request.ProjectId;


                _db.Relationships.Add(relationship);
                _db.SaveChanges();

                return("ONE ROW HAS BEEN ADDED TO ASSIGNMENT TABLE");
            }
            return("COULD NOT BEEN ADDED");
        }
Пример #30
0
        public void CannotCreateDuplicateRequest()
        {
            var key             = "UserFriend_CannotCreateDuplicateRequest";
            var friend          = CreateUser(key);
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, key);

            var relationshipRequest = new RelationshipRequest
            {
                RequestorId = loggedInAccount.User.Id,
                AcceptorId  = friend.Id,
                AutoAccept  = false
            };

            Fixture.SUGARClient.UserFriend.CreateFriendRequest(relationshipRequest);

            Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.UserFriend.CreateFriendRequest(relationshipRequest));
        }