private static void AddTag(ApplicationDbContext context) { IPropertiesService propertiesService = new PropertiesService(context); Console.WriteLine("Tag name:"); var tagName = Console.ReadLine(); Console.WriteLine("Importance (optional):"); bool isParsed = int.TryParse(Console.ReadLine(), out int tagImportance); int? importance = isParsed ? tagImportance : null; //var tags = new string[] //{ // "скъп-имот", // "евтин-имот", // "нов-имот", // "стар-имот", // "голям-имот", // "малък-имот", // "последен-етаж", // "първи-етаж", //}; ITagService tagService = new TagService(context, propertiesService); //foreach (var item in tags) //{ // var randomImportance = new Random().Next(0, 6); // tagService.Add(item, randomImportance); //} tagService.Add(tagName, importance); }
private static void AddTag(ApplicationDbContext db) { ITagService service = new TagService(db); while (true) { Console.WriteLine("Tag name:"); string tagName = Console.ReadLine(); if (db.Tags.FirstOrDefault(x => x.Name == tagName) != null) { Console.WriteLine("Tag already added!"); continue; } Console.WriteLine("Tag importance(optional)"); bool importanceParsed = int.TryParse(Console.ReadLine(), out int importanceInput); int? importance = null; if (importanceParsed) { importance = importanceInput; } service.Add(tagName, importance); Console.WriteLine("Continue adding tags? Press 'N' or 'H' for NO"); var key = Console.ReadKey(); Console.WriteLine(); if (key.KeyChar == 'N' || key.KeyChar == 'Н') { break; } } }
public ActionResult TagInsert(Tag tag) { tag.ID = Guid.NewGuid(); db.Add(tag); return(RedirectToAction("Index")); }
protected override void EstablishContext() { base.EstablishContext(); IoDevice = new Mock <IoDeviceAbstract>(); TagService.Add(IoDevice.Object); IoDevice2 = new Mock <IoDeviceAbstract>(); TagService.Add(IoDevice2.Object); }
private void AddTagButton_OnCLick(object sender, RoutedEventArgs e) { var window = new TagWindow(); if (window.ShowDialog() == false) { return; } var tag = new TagModel { Text = window.NewText, TagTextColor = "Black" }; _tagService.Add(tag); _tagsList.Add(tag); }
private static void AddTag(ApplicationDbContext db) { Console.Write("TagName:"); string name = Console.ReadLine(); Console.Write("Importance (optional) :"); int result; bool tryParse = int.TryParse(Console.ReadLine(), out result); ITagService service = new TagService(db, new PropertiesService(db)); if (tryParse) { service.Add(name, result); } else { service.Add(name); } }
public async Task <IActionResult> Create([Bind("Id,TextTag")] Tag tag) { if (!ModelState.IsValid) { return(View(tag)); } await _tagService.Add(tag); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([FromBody] Tag tag) { if (tag == null) { return(BadRequest()); } _tagService.Add(tag); await _unitOfWork.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created, tag)); }
private static void AddTag(ApplicationDbContext db) { Console.WriteLine("Tag name:"); string tagName = Console.ReadLine(); Console.WriteLine("Importance (optional):"); bool isParsed = int.TryParse(Console.ReadLine(), out int tagImportance); int? importance = isParsed ? tagImportance : null; IPropertiesService propertiesService = new PropertiesService(db); ITagService tagService = new TagService(db, propertiesService); tagService.Add(tagName, importance); }
public HttpResponseMessage Post(int entityTypeId, int ownerId, Guid entityGuid, string name, string entityQualifier = null, string entityQualifierValue = null, Guid?categoryGuid = null, bool?includeInactive = null) { SetProxyCreation(true); var person = GetPerson(); var personAlias = GetPersonAlias(); var tagService = new TagService((Rock.Data.RockContext)Service.Context); var tag = tagService.Get(entityTypeId, entityQualifier, entityQualifierValue, ownerId, name, categoryGuid, includeInactive); if (tag == null || !tag.IsAuthorized("Tag", person)) { int?categoryId = null; if (categoryGuid.HasValue) { var category = CategoryCache.Get(categoryGuid.Value); categoryId = category != null ? category.Id : (int?)null; } tag = new Tag(); tag.EntityTypeId = entityTypeId; tag.CategoryId = categoryId; tag.EntityTypeQualifierColumn = entityQualifier; tag.EntityTypeQualifierValue = entityQualifierValue; tag.OwnerPersonAliasId = new PersonAliasService((Rock.Data.RockContext)Service.Context).GetPrimaryAliasId(ownerId); tag.Name = name; tagService.Add(tag); } tag.TaggedItems = tag.TaggedItems ?? new Collection <TaggedItem>(); var taggedItem = tag.TaggedItems.FirstOrDefault(i => i.EntityGuid.Equals(entityGuid)); if (taggedItem == null) { taggedItem = new TaggedItem(); taggedItem.Tag = tag; taggedItem.EntityTypeId = entityTypeId; taggedItem.EntityGuid = entityGuid; tag.TaggedItems.Add(taggedItem); } System.Web.HttpContext.Current.Items.Add("CurrentPerson", person); Service.Context.SaveChanges(); return(ControllerContext.Request.CreateResponse(HttpStatusCode.Created, tag.Id)); }
}//GetEnumerator public override async Task <bool> AddIfNotExists(CsvRowResult row) { TagService service = new TagService(); Tag tag = row.Entity as Tag; if (await service.ExistsWithName(tag.Name)) { return(false); } else { await service.Add(tag); return(true); } } //AddIfNotExists
public ActionResult Create([Bind(Include = "Name,IsCanDelete,IsPublicTag,IsDynamic,Level,ViewOrder,ParentTagID")] Tag tag, bool sortByName = false, bool sortDesc = false) { if (ModelState.IsValid) { var res = service.Add(tag); if (!res.Success) { ModelState.AddModelError("", res.Message); } else { return(RedirectToAction("Index", "tags", new { id = tag.ParentTagID, success = true, sortByName = sortByName, sortDesc = sortDesc })); } } return(View(tag)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; TagService tagService = new TagService(); Tag tag = new Tag(); tag.tagname = context.Request["tagname1"]; tag.taglink = context.Request["taglink1"]; bool b; if (tagService.Add(tag) > 0) { b = true; } else { b = false; } context.Response.Write(b); context.Response.End(); }
public HttpResponseMessage Post(int entityTypeId, int ownerId, Guid entityGuid, string name, string entityQualifier, string entityQualifierValue) { var user = CurrentUser(); if (user != null) { using (new Rock.Data.UnitOfWorkScope()) { var tagService = new TagService(); var taggedItemService = new TaggedItemService(); var tag = tagService.Get(entityTypeId, entityQualifier, entityQualifierValue, ownerId, name); if (tag == null) { tag = new Tag(); tag.EntityTypeId = entityTypeId; tag.EntityTypeQualifierColumn = entityQualifier; tag.EntityTypeQualifierValue = entityQualifierValue; tag.OwnerId = ownerId; tag.Name = name; tagService.Add(tag, user.PersonId); tagService.Save(tag, user.PersonId); } var taggedItem = taggedItemService.Get(tag.Id, entityGuid); if (taggedItem == null) { taggedItem = new TaggedItem(); taggedItem.TagId = tag.Id; taggedItem.EntityGuid = entityGuid; taggedItemService.Add(taggedItem, user.PersonId); taggedItemService.Save(taggedItem, user.PersonId); } } return(ControllerContext.Request.CreateResponse(HttpStatusCode.Created)); } throw new HttpResponseException(HttpStatusCode.Unauthorized); }
public async Task Add_Test() { // arrange var fakeUowProvider = A.Fake <IUnitOfWorkProvider>(); var fakeRepoProvider = A.Fake <ITagRepositoryServiceProvider>(); var fakeUow = A.Fake <IUnitOfWork>(); var fakeRepo = A.Fake <ITagRepository>(); A.CallTo(() => fakeUowProvider.Get()).Returns(fakeUow); A.CallTo(() => fakeRepoProvider.Get(fakeUow)).Returns(fakeRepo); Tag tag = new Tag { Id = 1, Name = "tag" }; TagService service = new TagService(fakeUowProvider, fakeRepoProvider); // act await service.Add(tag); // assert A.CallTo(() => fakeRepo.Create(tag)).MustHaveHappened(); A.CallTo(() => fakeUow.Dispose()).MustHaveHappened(); }
private void AddButton_Click(object sender, RoutedEventArgs e) { if (FileNode.Tags.Count >= 3) { MessageBox.Show("您最多可以为该文件指派三个标签"); return; } var text = this.tagText.Text; if (string.IsNullOrEmpty(text)) { return; } if (tagService.IsExist(text, FileNode.FullName)) { return; } if (tagService.Add(text, FileNode.FullName)) { FileNode.Tags.Add(new TagEntity(text, FileNode.FullName)); } }
public HttpResponseMessage Post(int entityTypeId, int ownerId, Guid entityGuid, string name, string entityQualifier, string entityQualifierValue) { SetProxyCreation(true); var personAlias = GetPersonAlias(); var tagService = new TagService((Rock.Data.RockContext)Service.Context); var tag = tagService.Get(entityTypeId, entityQualifier, entityQualifierValue, ownerId, name); if (tag == null) { tag = new Tag(); tag.EntityTypeId = entityTypeId; tag.EntityTypeQualifierColumn = entityQualifier; tag.EntityTypeQualifierValue = entityQualifierValue; tag.OwnerPersonAliasId = new PersonAliasService((Rock.Data.RockContext)Service.Context).GetPrimaryAliasId(ownerId); tag.Name = name; tagService.Add(tag); } tag.TaggedItems = tag.TaggedItems ?? new Collection <TaggedItem>(); var taggedItem = tag.TaggedItems.FirstOrDefault(i => i.EntityGuid.Equals(entityGuid)); if (taggedItem == null) { taggedItem = new TaggedItem(); taggedItem.Tag = tag; taggedItem.EntityGuid = entityGuid; tag.TaggedItems.Add(taggedItem); } System.Web.HttpContext.Current.Items.Add("CurrentPerson", GetPerson()); Service.Context.SaveChanges(); return(ControllerContext.Request.CreateResponse(HttpStatusCode.Created, tag.Id)); }
/// <summary> /// Saves the tag values that user entered for the entity /// </summary> /// <param name="personAlias">The person alias.</param> public void SaveTagValues(PersonAlias personAlias) { int?currentPersonId = null; if (personAlias != null) { currentPersonId = personAlias.PersonId; } if (EntityGuid != Guid.Empty) { var rockContext = new RockContext(); var tagService = new TagService(rockContext); var taggedItemService = new TaggedItemService(rockContext); var person = currentPersonId.HasValue ? new PersonService(rockContext).Get(currentPersonId.Value) : null; // Get the existing tagged items for this entity var existingTaggedItems = new List <TaggedItem>(); foreach (var taggedItem in taggedItemService.Get(EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId, EntityGuid, CategoryGuid, ShowInactiveTags)) { if (taggedItem.IsAuthorized(Authorization.VIEW, person)) { existingTaggedItems.Add(taggedItem); } } // Get tag values after user edit var currentTags = new List <Tag>(); foreach (var serializedTag in Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { var tagName = GetNameFromSerializedTag(serializedTag); if (tagName.IsNullOrWhiteSpace()) { continue; } // Only if this is a new tag, create it var tag = tagService.Get(EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId, tagName, CategoryGuid, ShowInactiveTags); if (personAlias != null && tag == null) { tag = new Tag(); tag.EntityTypeId = EntityTypeId; tag.CategoryId = CategoryId; tag.EntityTypeQualifierColumn = EntityQualifierColumn; tag.EntityTypeQualifierValue = EntityQualifierValue; tag.OwnerPersonAliasId = personAlias.Id; tag.Name = tagName; tagService.Add(tag); } if (tag != null) { currentTags.Add(tag); } } rockContext.SaveChanges(); var currentNames = currentTags.Select(t => t.Name).ToList(); var existingNames = existingTaggedItems.Select(t => t.Tag.Name).ToList(); // Delete any tagged items that user removed foreach (var taggedItem in existingTaggedItems) { if (!currentNames.Contains(taggedItem.Tag.Name, StringComparer.OrdinalIgnoreCase) && taggedItem.IsAuthorized(Rock.Security.Authorization.TAG, person)) { existingNames.Remove(taggedItem.Tag.Name); taggedItemService.Delete(taggedItem); } } rockContext.SaveChanges(); // Add any tagged items that user added foreach (var tag in currentTags) { // If the tagged item was not already there, and (it's their personal tag OR they are authorized to use it) then add it. if (!existingNames.Contains(tag.Name, StringComparer.OrdinalIgnoreCase) && ( (tag.OwnerPersonAliasId != null && tag.OwnerPersonAliasId == personAlias?.Id) || tag.IsAuthorized(Rock.Security.Authorization.TAG, person) ) ) { var taggedItem = new TaggedItem(); taggedItem.TagId = tag.Id; taggedItem.EntityTypeId = this.EntityTypeId; taggedItem.EntityGuid = EntityGuid; taggedItemService.Add(taggedItem); } } rockContext.SaveChanges(); } }
public async System.Threading.Tasks.Task <PostEntity> GetPostEntityAsync(PostEditViewModel data, CategoryService categoryService, TagService tagService) { try { if (data == null) { throw new ArgumentNullException(); } var postId = Guid.NewGuid(); var postContent = HttpUtility.HtmlEncode(data.HtmlContent); var shortContent = !string.IsNullOrWhiteSpace(data.ShortContent) ? data.ShortContent : Utility.GetPostAbstract(data.HtmlContent, CodeMazeConfiguration.AppSettings.PostSummaryWords); var newTime = DateTime.UtcNow; var postCode = !string.IsNullOrWhiteSpace(data.Code) ? data.Code : data.Title.ConvertToCode(); var postUrl = !string.IsNullOrWhiteSpace(data.Url) ? data.Url : data.Title.ConvertToUrl(); var postModel = new PostEntity { CommentEnabled = data.EnableComment, Id = postId, PostContent = postContent, ContentAbstract = shortContent, CreateOnUtc = newTime, Code = postCode, Url = postUrl, Title = data.Title.Trim(), IsDeleted = false, IsPublished = data.IsPublished, PubDateUtc = data.IsPublished ? newTime : (DateTime?)null, ExposedToSiteMap = data.ExposedToSiteMap, IsFeedIncluded = data.IsFeedIncluded, PostExtension = new PostExtensionEntity { Hits = 0, Likes = 0 } }; // add categories if (data.CategoryIds?.Length > 0) { var categoriesExists = await categoryService.CheckExistsAsync(data.CategoryIds.ToList()); foreach (var cid in categoriesExists) { postModel.PostCategory.Add(new PostCategoryEntity { CategoryId = cid, PostId = postModel.Id }); } } // add tags if (null != data.Tags && data.Tags.Length > 0) { var tagList = data.Tags.Split(','); foreach (string tagItem in tagList) { var getTag = tagService.GetTag(tagItem.ConvertToUrl()); var tagid = -1; if (getTag != null) { tagid = getTag.Id; } if (getTag == null) { var newTag = new TagEntity { DisplayName = tagItem.RemoveMultipleWhiteSpaces(), NormalizedName = tagItem.ConvertToUrl() }; var tagAdded = tagService.Add(newTag); if (tagAdded != null) { tagid = tagAdded.Id; } } postModel.PostTag.Add(new PostTagEntity { TagId = tagid, PostId = postModel.Id }); } } return(postModel); } catch (Exception ex) { throw; } }
/// <summary> /// Saves the tag values that user entered for the entity ( /// </summary> /// <param name="currentPersonId">The current person identifier.</param> public void SaveTagValues(int?currentPersonId) { if (EntityGuid != Guid.Empty) { var tagService = new TagService(); var taggedItemService = new TaggedItemService(); // Get the existing tags for this entity type var existingTags = tagService.Get(EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId).ToList(); // Get the existing tagged items for this entity var existingTaggedItems = taggedItemService.Get(EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId, EntityGuid); // Get tag values after user edit var currentTags = new List <Tag>(); foreach (var value in this.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { string tagName = value; if (tagName.Contains('^')) { tagName = tagName.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries)[0]; } // If this is a new tag, create it Tag tag = existingTags.FirstOrDefault(t => t.Name.Equals(tagName, StringComparison.OrdinalIgnoreCase)); if (tag == null && currentPersonId != null) { tag = new Tag(); tag.EntityTypeId = EntityTypeId; tag.EntityTypeQualifierColumn = EntityQualifierColumn; tag.EntityTypeQualifierValue = EntityQualifierValue; tag.OwnerId = currentPersonId.Value; tag.Name = tagName; tagService.Add(tag, currentPersonId); tagService.Save(tag, currentPersonId); } if (tag != null) { currentTags.Add(tag); } } // Delete any tagged items that user removed var names = currentTags.Select(t => t.Name).ToList(); foreach (var taggedItem in existingTaggedItems) { if (!names.Contains(taggedItem.Tag.Name, StringComparer.OrdinalIgnoreCase)) { taggedItemService.Delete(taggedItem, currentPersonId); taggedItemService.Save(taggedItem, currentPersonId); } } // Add any tagged items that user added names = existingTaggedItems.Select(t => t.Tag.Name).ToList(); foreach (var tag in currentTags) { if (!names.Contains(tag.Name, StringComparer.OrdinalIgnoreCase)) { var taggedItem = new TaggedItem(); taggedItem.TagId = tag.Id; taggedItem.EntityGuid = EntityGuid; taggedItemService.Add(taggedItem, currentPersonId); taggedItemService.Save(taggedItem, currentPersonId); } } } }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages) { errorMessages = new List <string>(); // get the tag string tagName = GetAttributeValue(action, "OrganizationTag").ResolveMergeFields(GetMergeFields(action));; if (!string.IsNullOrEmpty(tagName)) { // get person entity type var personEntityType = Rock.Web.Cache.EntityTypeCache.Read("Rock.Model.Person"); // get tag TagService tagService = new TagService(rockContext); Tag orgTag = tagService.Queryable().Where(t => t.Name == tagName && t.EntityTypeId == personEntityType.Id && t.OwnerPersonAlias == null).FirstOrDefault(); if (orgTag == null) { // add tag first orgTag = new Tag(); orgTag.Name = tagName; orgTag.EntityTypeQualifierColumn = string.Empty; orgTag.EntityTypeQualifierValue = string.Empty; orgTag.EntityTypeId = personEntityType.Id; tagService.Add(orgTag); rockContext.SaveChanges(); // new up a list of items for later count orgTag.TaggedItems = new List <TaggedItem>(); } // get the person and add them to the tag string value = GetAttributeValue(action, "Person"); Guid guidPersonAttribute = value.AsGuid(); if (!guidPersonAttribute.IsEmpty()) { var attributePerson = AttributeCache.Read(guidPersonAttribute, rockContext); if (attributePerson != null) { string attributePersonValue = action.GetWorklowAttributeValue(guidPersonAttribute); if (!string.IsNullOrWhiteSpace(attributePersonValue)) { if (attributePerson.FieldType.Class == "Rock.Field.Types.PersonFieldType") { Guid personAliasGuid = attributePersonValue.AsGuid(); if (!personAliasGuid.IsEmpty()) { var person = new PersonAliasService(rockContext).Queryable() .Where(a => a.Guid.Equals(personAliasGuid)) .Select(a => a.Person) .FirstOrDefault(); if (person != null) { // add person to tag if they are not already in it if (orgTag.TaggedItems.Where(i => i.EntityGuid == person.PrimaryAlias.AliasPersonGuid && i.TagId == orgTag.Id).Count() == 0) { TaggedItem taggedPerson = new TaggedItem(); taggedPerson.Tag = orgTag; taggedPerson.EntityGuid = person.PrimaryAlias.AliasPersonGuid; orgTag.TaggedItems.Add(taggedPerson); rockContext.SaveChanges(); } else { action.AddLogEntry(string.Format("{0} already tagged with {1}", person.FullName, orgTag.Name)); } return(true); } else { errorMessages.Add(string.Format("Person could not be found for selected value ('{0}')!", guidPersonAttribute.ToString())); } } } else { errorMessages.Add("The attribute used to provide the person was not of type 'Person'."); } } } } } else { errorMessages.Add("No organization tag was provided"); } errorMessages.ForEach(m => action.AddLogEntry(m, true)); return(true); }
/// <summary> /// Saves the tag values that user entered for the entity ( /// </summary> /// <param name="personAlias">The person alias.</param> public void SaveTagValues(PersonAlias personAlias) { int?currentPersonId = null; if (personAlias != null) { currentPersonId = personAlias.PersonId; } if (EntityGuid != Guid.Empty) { var rockContext = new RockContext(); var tagService = new TagService(rockContext); var taggedItemService = new TaggedItemService(rockContext); var person = currentPersonId.HasValue ? new PersonService(rockContext).Get(currentPersonId.Value) : null; // Get the existing tagged items for this entity var existingTaggedItems = new List <TaggedItem>(); foreach (var taggedItem in taggedItemService.Get(EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId, EntityGuid, CategoryGuid, ShowInActiveTags)) { if (taggedItem.IsAuthorized(Authorization.VIEW, person)) { existingTaggedItems.Add(taggedItem); } } // Get tag values after user edit var currentTags = new List <Tag>(); foreach (var value in this.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { string tagName = value; if (tagName.Contains('^')) { tagName = tagName.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries)[0]; } // If this is a new tag, create it Tag tag = tagService.Get(EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId, tagName, CategoryGuid, ShowInActiveTags); if ((tag == null || !tag.IsAuthorized("Tag", person)) && personAlias != null) { tag = new Tag(); tag.EntityTypeId = EntityTypeId; tag.CategoryId = CategoryId; tag.EntityTypeQualifierColumn = EntityQualifierColumn; tag.EntityTypeQualifierValue = EntityQualifierValue; tag.OwnerPersonAliasId = personAlias.Id; tag.Name = tagName; tagService.Add(tag); } if (tag != null) { currentTags.Add(tag); } } rockContext.SaveChanges(); var currentNames = currentTags.Select(t => t.Name).ToList(); var existingNames = existingTaggedItems.Select(t => t.Tag.Name).ToList(); // Delete any tagged items that user removed foreach (var taggedItem in existingTaggedItems) { if (!currentNames.Contains(taggedItem.Tag.Name, StringComparer.OrdinalIgnoreCase) && taggedItem.IsAuthorized("Tag", person)) { existingNames.Remove(taggedItem.Tag.Name); taggedItemService.Delete(taggedItem); } } rockContext.SaveChanges(); // Add any tagged items that user added foreach (var tag in currentTags) { if (tag.IsAuthorized("Tag", person) && !existingNames.Contains(tag.Name, StringComparer.OrdinalIgnoreCase)) { var taggedItem = new TaggedItem(); taggedItem.TagId = tag.Id; taggedItem.EntityTypeId = this.EntityTypeId; taggedItem.EntityGuid = EntityGuid; taggedItemService.Add(taggedItem); } } rockContext.SaveChanges(); } }