public async Task AddLeafTag_Test() { // Root CreateTagDto createRootTagDto = new CreateTagDto { Name = "Root" }; var rootTagDto = await tagAppService.Create(createRootTagDto); // Sub CreateTagDto createSubTagDto = new CreateTagDto { Name = "Sub", ParentId = rootTagDto.Id }; var subTagDto = await tagAppService.Create(createSubTagDto); // Leaf CreateTagDto createLeafTagDto = new CreateTagDto { Name = "Leaf", ParentId = subTagDto.Id }; var leafTagDto = await tagAppService.Create(createLeafTagDto); // Unit test project does not support lazy loading. // Navigation properties need eager loading. await UsingDbContextAsync(async context => { Tag resultTag = await context.Tags.Include(t => t.Parent) .ThenInclude(t => t.Parent).FirstOrDefaultAsync(t => t.Id == leafTagDto.Id); resultTag.Name.ShouldBe("Leaf"); resultTag.FullName.ShouldBe("Root>>Sub>>Leaf"); resultTag.ParentId.ShouldBe(subTagDto.Id); resultTag.Parent.Name.ShouldBe("Sub"); resultTag.Parent.Children.Count.ShouldBe(1); resultTag.Children.Count.ShouldBe(0); }); }
public int Add(CreateTagDto prod) { using (IDbConnection dbConnection = Connection) { return(dbConnection.ExecuteScalar <int>(TagQueries.Add, prod)); } }
//public async Task<bool> CreateTagAsync(CreateTagDto input) //{ // PermissionChecker.Authorize(PermissionNames.Page_Tag_Add); // var obj = await _tagRepository.FirstOrDefaultAsync(p => p.Title == input.Title && p.CreatorUserId == AbpSession.UserId); // if (obj != null) // { // CheckErrors(IdentityResult.Failed(new IdentityError() { Code = "308", Description = L("CreateTagError") })); // } // //Tag tag = new Tag(); // //tag.Title = input.Title; // var tag = Mapper.Map<Tag>(input); // //var task = ObjectMapper.Map<Tag>(input); // return await _tagRepository.InsertAndGetIdAsync(tag) > 0; //} public async Task <IdentityResult> CreateTagAsync(CreateTagDto input) { PermissionChecker.Authorize(PermissionNames.Page_Tag_Add); var obj = await _tagRepository.FirstOrDefaultAsync(p => p.Title == input.Title && p.CreatorUserId == AbpSession.UserId); if (obj != null) { return(IdentityResult.Failed(new IdentityError() { Code = "308", Description = L("CreateTagError") })); } //Tag tag = new Tag(); //tag.Title = input.Title; var tag = Mapper.Map <Tag>(input); //var task = ObjectMapper.Map<Tag>(input); if (await _tagRepository.InsertAndGetIdAsync(tag) > 0) { return(IdentityResult.Success); } return(IdentityResult.Failed(new IdentityError() { Code = "500", Description = L("CreateTagError") })); }
private async Task CreateTagTree3() { // Root 3 CreateTagDto createRoot3TagDto = new CreateTagDto { Name = "Root3" }; var root3TagDto = await tagAppService.Create(createRoot3TagDto); }
public bool Add(CreateTagDto tag) { if (_tagRepository.Add(tag) != 0) { return(true); } return(false); }
private long CreateTag(CreateTagDto tag, SqliteConnection db, SqliteTransaction txn) { var tagCommand = new SqliteCommand("INSERT INTO tag(type, name, deleted, unique_id) VALUES (@TagType, @TagName, false, @UniqueId)", db, txn); tagCommand.Parameters.AddWithValue("@TagType", tag.Type); tagCommand.Parameters.AddWithValue("@TagName", tag.Name); tagCommand.Parameters.AddWithValue("@UniqueId", UniqueIdUtil.GenerateUniqueId()); tagCommand.ExecuteNonQuery(); return(QueryUtil.GetLastInsertedPrimaryKey(db, txn)); }
public IActionResult AddProblemTag([FromBody] CreateTagDto value) { if (ModelState.IsValid) { if (_tagService.Add(value)) { return(Ok()); } } return(BadRequest()); }
public async Task <TagDto> CreateAsync(CreateTagDto input) { var newTag = await _tagRepository.InsertAsync( new Tag( input.Name, input.Description ) ); return(ObjectMapper.Map <Tag, TagDto>(newTag)); }
public IActionResult Post(int problemId, [FromBody] CreateTagDto value) { if (ModelState.IsValid) { var result = _tagService.AddProblemTag(value, problemId); if (result != null) { return(Ok(result)); } } return(BadRequest()); }
public async Task GetByName_Test() { // Root 1 CreateTagDto createRoot1TagDto = new CreateTagDto { Name = "Root1" }; var root1TagDto = await tagAppService.Create(createRoot1TagDto); // Sub 11 CreateTagDto createSub11TagDto = new CreateTagDto { Name = "Sub11", ParentId = root1TagDto.Id }; var sub11TagDto = await tagAppService.Create(createSub11TagDto); // Leaf 111 CreateTagDto createLeaf111TagDto = new CreateTagDto { Name = "Leaf111", ParentId = sub11TagDto.Id }; var leaf111TagDto = await tagAppService.Create(createLeaf111TagDto); // Leaf 112 CreateTagDto createLeaf112TagDto = new CreateTagDto { Name = "Leaf112", ParentId = sub11TagDto.Id }; var leaf112TagDto = await tagAppService.Create(createLeaf112TagDto); // Sub 12 CreateTagDto createSub12TagDto = new CreateTagDto { Name = "Sub12", ParentId = root1TagDto.Id }; var sub12TagDto = await tagAppService.Create(createSub12TagDto); // Leaf 121 CreateTagDto createLeaf121TagDto = new CreateTagDto { Name = "Leaf111", ParentId = sub12TagDto.Id }; var leaf121TagDto = await tagAppService.Create(createLeaf121TagDto); // Leaf 122 CreateTagDto createLeaf122TagDto = new CreateTagDto { Name = "Leaf112", ParentId = sub12TagDto.Id }; var leaf122TagDto = await tagAppService.Create(createLeaf122TagDto); ICollection <TagDto> tags1 = await tagAppService.GetByName("111"); tags1.Count.ShouldBe(2); ICollection <TagDto> tags2 = await tagAppService.GetByName("12"); tags2.Count.ShouldBe(3); }
public async Task GetTargetsOfTagAsync_Tests() { string Sql1 = @"SELECT Id, Name FROM Product WHERE VisibleIndividually = @vi AND ApprovedRatingSum = @ars"; IList <MetaEntity> metaEntities1 = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql1, new { vi = 1, ars = 4 }); MetaEntitySyncResult result1 = metaEntityManager.SyncEntityToTarget(metaEntities1); // Root 1 CreateTagDto createRoot1TagDto = new CreateTagDto { Name = "Root1" }; var root1TagDto = await tagAppService.Create(createRoot1TagDto); // Sub 11 CreateTagDto createSub11TagDto = new CreateTagDto { Name = "Sub11", ParentId = root1TagDto.Id }; var sub11TagDto = await tagAppService.Create(createSub11TagDto); // Leaf 111 CreateTagDto createLeaf111TagDto = new CreateTagDto { Name = "Leaf111", ParentId = sub11TagDto.Id }; var leaf111TagDto = await tagAppService.Create(createLeaf111TagDto); Tag tag = tagRepository.FirstOrDefault(leaf111TagDto.Id); tagTargetManager.AssignTag(result1.Targets, tag); IList <TagTarget> tagTargets = tagTargetRepository.GetAllList(); tagTargets.Count.ShouldBe(18); using (var context = Resolve <StarryNightDbContext>()) { Tag tagResult = context.Tags .Include(t => t.TagTargets) .ThenInclude(tt => tt.Target) .FirstOrDefault(t => t.Id == leaf111TagDto.Id); tagResult.TagTargets.Count.ShouldBe(18); ICollection <Target> taggedTargets1 = tagManager.GetTargetsOfTag(tagResult, 10, 0); taggedTargets1.Count.ShouldBe(10); ICollection <Target> taggedTargets2 = tagManager.GetTargetsOfTag(tagResult, 10, 10); taggedTargets2.Count.ShouldBe(8); ICollection <Target> taggedTargets3 = tagManager.GetTargetsOfTag(tagResult, 100, 0); taggedTargets3.Count.ShouldBe(18); } }
private long CreateTag(CreateTagDto tag, string tableName) { using (var db = DataAccessUtil.CreateSqlConnection()) { db.Open(); using (var txn = db.BeginTransaction()) { var tagId = CreateTag(tag, db, txn); var tagCommand = new SqliteCommand($"INSERT INTO {tableName} VALUES (@TagId)", db, txn); tagCommand.Parameters.AddWithValue("@TagId", tagId); tagCommand.ExecuteNonQuery(); txn.Commit(); return(tagId); } } }
public TagDto AddProblemTag(CreateTagDto tag, int problemId) { var result = _tagRepository.Add(tag); if (result != 0) { var problemTag = new TagDto { Name = tag.Name, Id = result }; AddToProblem(result, problemId); return(problemTag); } return(null); }
public async Task AddRootTag_Test() { // Root CreateTagDto createRootTagDto = new CreateTagDto { Name = "Root" }; var rootTagDto = await tagAppService.Create(createRootTagDto); var outputDto = await tagAppService.Get(new EntityDto <long> { Id = rootTagDto.Id }); outputDto.Name.ShouldBe("Root"); outputDto.FullName.ShouldBe("Root"); outputDto.Parent.ShouldBe(null); outputDto.Children.Count.ShouldBe(0); }
public async Task AssignTag_Tests() { string Sql1 = @"SELECT Id, Name FROM Product"; IList <MetaEntity> metaEntities1 = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql1); MetaEntitySyncResult result1 = metaEntityManager.SyncEntityToTarget(metaEntities1); string Sql2 = @"SELECT Id, Name FROM Product WHERE VisibleIndividually = @param"; IList <MetaEntity> metaEntities2 = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql2, new { param = 0 }); MetaEntitySyncResult result2 = metaEntityManager.SyncEntityToTarget(metaEntities2); // Root 1 CreateTagDto createRoot1TagDto = new CreateTagDto { Name = "Root1" }; var root1TagDto = await tagAppService.Create(createRoot1TagDto); // Sub 11 CreateTagDto createSub11TagDto = new CreateTagDto { Name = "Sub11", ParentId = root1TagDto.Id }; var sub11TagDto = await tagAppService.Create(createSub11TagDto); // Leaf 111 CreateTagDto createLeaf111TagDto = new CreateTagDto { Name = "Leaf111", ParentId = sub11TagDto.Id }; var leaf111TagDto = await tagAppService.Create(createLeaf111TagDto); AssignTagDto assignTagDto = new AssignTagDto() { Type = MetaEntityType.Product, Sql = @"SELECT Id, Name FROM Product WHERE VisibleIndividually = @param", Param = "{ \"param\": 0 }", TagId = leaf111TagDto.Id }; tagTargetAppService.AssignTag(assignTagDto); IList <TagTarget> tagTargets = tagTargetRepository.GetAllList(); tagTargets.Count.ShouldBe(2); tagTargets[0].TagId.ShouldBe(3); tagTargets[0].TargetId.ShouldBe(14); tagTargets[1].TagId.ShouldBe(3); tagTargets[1].TargetId.ShouldBe(15); }
private async Task CreateTagTree1() { // Root 1 CreateTagDto createRoot1TagDto = new CreateTagDto { Name = "Root1" }; var root1TagDto = await tagAppService.Create(createRoot1TagDto); // Sub 11 CreateTagDto createSub11TagDto = new CreateTagDto { Name = "Sub11", ParentId = root1TagDto.Id }; var sub11TagDto = await tagAppService.Create(createSub11TagDto); // Leaf 111 CreateTagDto createLeaf111TagDto = new CreateTagDto { Name = "Leaf111", ParentId = sub11TagDto.Id }; var leaf111TagDto = await tagAppService.Create(createLeaf111TagDto); // Leaf 112 CreateTagDto createLeaf112TagDto = new CreateTagDto { Name = "Leaf112", ParentId = sub11TagDto.Id }; var leaf112TagDto = await tagAppService.Create(createLeaf112TagDto); // Sub 12 CreateTagDto createSub12TagDto = new CreateTagDto { Name = "Sub12", ParentId = root1TagDto.Id }; var sub12TagDto = await tagAppService.Create(createSub12TagDto); // Leaf 121 CreateTagDto createLeaf121TagDto = new CreateTagDto { Name = "Leaf111", ParentId = sub12TagDto.Id }; var leaf121TagDto = await tagAppService.Create(createLeaf121TagDto); // Leaf 122 CreateTagDto createLeaf122TagDto = new CreateTagDto { Name = "Leaf112", ParentId = sub12TagDto.Id }; var leaf122TagDto = await tagAppService.Create(createLeaf122TagDto); }
private async Task CreateTagTree2() { // Root 2 CreateTagDto createRoot2TagDto = new CreateTagDto { Name = "Root2" }; var root2TagDto = await tagAppService.Create(createRoot2TagDto); // Sub 21 CreateTagDto createSub21TagDto = new CreateTagDto { Name = "Sub21", ParentId = root2TagDto.Id }; var sub21TagDto = await tagAppService.Create(createSub21TagDto); // Leaf 211 CreateTagDto createLeaf211TagDto = new CreateTagDto { Name = "Leaf211", ParentId = sub21TagDto.Id }; var leaf211TagDto = await tagAppService.Create(createLeaf211TagDto); }
public async Task GetTagByNameAsync_Tests() { // Root 1 CreateTagDto createRoot1TagDto = new CreateTagDto { Name = "Root1" }; var root1TagDto = await tagAppService.Create(createRoot1TagDto); // Sub 11 CreateTagDto createSub11TagDto = new CreateTagDto { Name = "Sub11", ParentId = root1TagDto.Id }; var sub11TagDto = await tagAppService.Create(createSub11TagDto); // Leaf 111 CreateTagDto createLeaf111TagDto = new CreateTagDto { Name = "Leaf111", ParentId = sub11TagDto.Id }; var leaf111TagDto = await tagAppService.Create(createLeaf111TagDto); ICollection <Tag> tags1 = await tagManager.GetTagsByNameAsync("Root"); tags1.Count.ShouldBe(1); ICollection <Tag> tags2 = await tagManager.GetTagsByNameAsync("Sub"); tags2.Count.ShouldBe(1); ICollection <Tag> tags3 = await tagManager.GetTagsByNameAsync("Leaf"); tags3.Count.ShouldBe(1); ICollection <Tag> tags4 = await tagManager.GetTagsByNameAsync("11"); tags4.Count.ShouldBe(2); ICollection <Tag> tags5 = await tagManager.GetTagsByNameAsync("1"); tags5.Count.ShouldBe(3); }
public JObject CreateTag(CreateTagDto dto) { JObject jo = new JObject(); if (dto.Tag_name.Length > 100) { jo["stateCode"] = 400; jo["message"] = "标签名长度大于100个字符,无法添加!"; return(jo); } else if (dto.Tag_name == "") { jo["stateCode"] = 400; jo["message"] = "标签名不能为空,无法添加!"; return(jo); } var isRepeat = WebapiDbContext.Tags.Where(o => o.Tag_name == dto.Tag_name).FirstOrDefault(); if (isRepeat != null) { jo["stateCode"] = 400; jo["message"] = "存在重复标签名,无法添加!"; return(jo); } else { WebapiDbContext.Tags.Add(new Repository.Entity.Tag() { Tag_name = dto.Tag_name, Is_deleted = "否", Created_at = DateTime.Now, Updated_at = DateTime.Now }); WebapiDbContext.SaveChanges(); jo["stateCode"] = 200; jo["message"] = "success!"; return(jo); } }
public async Task <IActionResult> CreateTag([FromBody] CreateTagDto tag) { var tags = await _mediator.Send(new GetAllTagsQuery() { Parameters = new TagParameters { Name = tag.Name } }); if (tags.Any()) { return(BadRequest("This record is already available!")); } var tagEntity = _mapper.Map <Tag>(tag); await _mediator.Send(new CreateTagCommand() { NewTag = tagEntity }); await _messageHubContext.Clients.All.SendAsync("ReceiveMessage", $"New tag added. Tag name: {tag.Name}"); return(Ok()); }
public IActionResult CreateTag([FromServices] IWebapiService webapiService, [FromBody] CreateTagDto dto) { return(Json(webapiService.CreateTag(dto))); }
/// <summary> /// Creates the tag if it does not exist and adds a Tag reference to the unit, /// Draft /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// The id of the Unit /// </param> /// <param name='newTag'> /// The tag to create or reference /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async System.Threading.Tasks.Task <object> PostTagAsyncByidnewTagAsync(this IUnits operations, int id, CreateTagDto newTag, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { using (var _result = await operations.PostTagAsyncByidnewTagWithHttpMessagesAsync(id, newTag, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates the tag if it does not exist and adds a Tag reference to the unit, /// Draft /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// The id of the Unit /// </param> /// <param name='newTag'> /// The tag to create or reference /// </param> public static object PostTagAsyncByidnewTag(this IUnits operations, int id, CreateTagDto newTag) { return(System.Threading.Tasks.Task.Factory.StartNew(s => ((IUnits)s).PostTagAsyncByidnewTagAsync(id, newTag), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }