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; }
private async Task <OperationResult <bool> > PostTag(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(); //check if tags exist when have the tags service.... if (community.Result.tag.Any(elem => newTags.Contains(elem.id))) { return new OperationResult <bool>() { Success = false, Message = Messages.COMMUNITY_TAG_EXIST } } ; try { var success = await communityRepo.InsertTag(communityId, newTags); scope.Complete(); return(new OperationResult <bool>() { Success = true, Message = Messages.TAG_INSERTED, Result = true }); } catch (Exception ex) { return(new OperationResult <bool>() { Success = false, Message = ex.InnerException.Message, Result = false }); } } }