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;
        }
Esempio n. 2
0
        private async Task <OperationResult <string> > PostMember(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_MEMBER
                           }
                }
                ;

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

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