public ActionResult AddTag(string tq) { if (!(tq == "")) { QuestionModel q = new QuestionModel(); q = QuestionModel.GetLastQuestion(); int s = 0; s = q.QuestionId; TagModel.AddTag(tq, s); } //QuestionModel.AddQuestion(ques); return(RedirectToAction("PostQuestions")); }
public HttpResponseMessage Post(string link, TagReference tag) { try { TagModel.AddTag(link, tag.Id, tag.Type); var result = new { included = TagModel.ListTags(tag.Id, tag.Type), common = TagModel.ListCommon(tag.Id, tag.Type) }; return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public async Task <TagData> SaveTagModel(string tagName) { var store = ServiceContainer.Resolve <IDataStore>(); var existing = await store.Table <TagData>() .Where(r => r.WorkspaceId == workspaceId && r.Name == tagName) .ToListAsync().ConfigureAwait(false); TagData tag; if (existing.Count > 0) { tag = existing.FirstOrDefault(); } else { tag = await TagModel.AddTag(workspaceId, tagName); } return(tag); }
private async Task <List <TagData> > UpdateTagsWithWorkspace(Guid timeEntryId, Guid workspaceId, List <TagData> oldTagList) { var dataStore = ServiceContainer.Resolve <IDataStore> (); // Get new workspace tag list. var tagList = await dataStore.Table <TagData> () .Where(r => r.WorkspaceId == workspaceId && r.DeletedAt == null) .ToListAsync(); // Get new tags to create and existing tags from previous workspace. var tagsToCreate = new List <TagData> (oldTagList.Where(t => tagList.IndexOf(n => n.Name.Equals(t.Name)) == -1)); var commonTags = new List <TagData> (tagList.Where(t => oldTagList.IndexOf(n => n.Name.Equals(t.Name)) != -1)); // Create new tags. for (int i = 0; i < tagsToCreate.Count; i++) { var newTag = await TagModel.AddTag(workspaceId, tagsToCreate[i].Name); tagsToCreate[i] = newTag; } // Contact both lists. var newTagList = commonTags.Concat(tagsToCreate); // Delete existing tag relationships from relationship table. var oldRelationships = await dataStore.Table <TimeEntryTagData> () .Where(t => t.TimeEntryId == timeEntryId && t.DeletedAt == null) .ToListAsync(); oldRelationships.ForEach(async(r) => await dataStore.DeleteAsync(r)); // Create and save new relationships foreach (var item in newTagList) { var r = new TimeEntryTagData { TagId = item.Id, TimeEntryId = timeEntryId }; await dataStore.PutAsync(r); } return(newTagList.ToList()); }