예제 #1
0
        public void InsertCommunityMember()
        {
            string id        = com.InsertMember(3, "2").Result;
            var    community = com.GetByIdAsync(3).Result;

            Assert.AreEqual(2, community.members.Count);

            string id2 = com.DeleteMember(3, "2").Result;
        }
예제 #2
0
        private async Task <OperationResult <string> > DeleteMember(int communityId, string userId)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var community = await GetByIdAsync(communityId);

                var user = await userService.GetByIdAsync(userId);

                if (!community.Success)
                {
                    return new OperationResult <string>()
                           {
                               Success = false, Message = community.Message
                           }
                }
                ;
                if (!user.Success)
                {
                    return new OperationResult <string>()
                           {
                               Success = false, Message = user.Message
                           }
                }
                ;
                if (!community.Result.members.Select(elem => elem.id).Contains(userId))
                {
                    return new OperationResult <string>()
                           {
                               Success = false, Message = Messages.COMMUNITY_HAS_NO_MEMBER
                           }
                }
                ;

                try
                {
                    var id = await communityRepo.DeleteMember(communityId, userId);

                    scope.Complete();
                    return(new OperationResult <string>()
                    {
                        Success = true, Message = Messages.COMMUNITY_MEMBER_DELETED, Result = id
                    });
                }
                catch (Exception ex)
                {
                    return(new OperationResult <string>()
                    {
                        Success = false, Message = ex.InnerException.Message
                    });
                }
            }
        }