private async Task <OperationResult <bool> > DeleteTag(int communityId, int[] tags, string adminId) { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var community = await GetByIdAsync(communityId); if (!community.Success) { return new OperationResult <bool>() { Success = false, Message = community.Message } } ; if (!community.Result.admins.Select(elem => elem.id).Contains(adminId)) { return new OperationResult <bool>() { Success = false, Message = Messages.USER_NOT_ADMIN } } ; var newTags = tags.Distinct().ToArray(); var currentTags = community.Result.tag.Select(x => x.id); if (!newTags.All(elem => currentTags.Contains(elem))) { return new OperationResult <bool>() { Success = false, Message = Messages.COMMUNITY_TAG_NOT_EXIST } } ; try { var id = await communityRepo.DeleteTag(communityId, newTags); scope.Complete(); return(new OperationResult <bool>() { Success = true, Message = Messages.COMMUNITY_TAG_DELETED, Result = true }); } catch (Exception ex) { return(new OperationResult <bool>() { Success = false, Message = ex.InnerException.Message, Result = false }); } } } } }
public void InsertCommunityTag() { bool success = com.InsertTag(1, new int[] { 1, 2 }).Result; var community = com.GetByIdAsync(1).Result; Assert.AreEqual(4, community.tag.Count); Assert.IsNotNull(community.tag.First(t => t.name == "java")); Assert.IsNotNull(community.tag.First(t => t.name == "eclipse")); bool id2 = com.DeleteTag(1, new int[] { 1, 2 }).Result; }