示例#1
0
        private async Task <OperationResult <int> > Delete(CreateCommunity item)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var community = await GetByIdAsync(item.Id);

                if (!community.Success)
                {
                    return new OperationResult <int>()
                           {
                               Success = false, Message = community.Message
                           }
                }
                ;
                if (!community.Result.admins.Select(elem => elem.id).Contains(item.UserId))
                {
                    return new OperationResult <int>()
                           {
                               Success = false, Message = "the user with id(" + item.UserId + ") does not have permission to delete this community"
                           }
                }
                ;

                try
                {
                    var id = await communityRepo.DeleteAsync(community.Result);

                    scope.Complete();
                    ImageService.DeleteFolder(item.Name, ImageService.ImageIdentity.Communities);
                    return(new OperationResult <int>()
                    {
                        Success = true, Message = Messages.COMMUNITY_DELETED_SUCCESS, Result = id
                    });
                }
                catch (Exception ex)
                {
                    return(new OperationResult <int>()
                    {
                        Success = false, Message = ex.InnerException.Message
                    });
                }
            }
        }
        public void CreateCommunity()
        {
            int newCommunityID = 0;

            try
            {
                newCommunityID = com.PostAsync(new CreateCommunity()
                {
                    Name = "Break", Local = "rua street", Description = "somos breakers", FoundationDate = DateTime.Now, UserId = "2", Tags = new int[] { 4, 3 }
                }).Result;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentException));
            }
            var res = com.GetByIdAsync(newCommunityID).Result;

            Assert.AreEqual(res.name, "Break");
            Assert.AreEqual(2, res.tag.Count());
            var id = com.DeleteAsync(res).Result;
        }