public void InsertCommunityAdmin()
        {
            string id        = com.InsertAdmin(3, "2").Result;
            var    community = com.GetByIdAsync(3).Result;

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

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

                if (!community.Success)
                {
                    return new OperationResult <string>()
                           {
                               Success = false, Message = community.Message
                           }
                }
                ;
                if (!community.Result.admins.Select(elem => elem.id).Contains(adminId))
                {
                    return new OperationResult <string>()
                           {
                               Success = false, Message = Messages.USER_NOT_ADMIN
                           }
                }
                ;
                if (!community.Result.admins.Select(elem => elem.id).Contains(userId))
                {
                    return new OperationResult <string>()
                           {
                               Success = false, Message = Messages.COMMUNITY_HAS_NO_ADMIN
                           }
                }
                ;

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

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