public async Task <IActionResult> DeleteTag(int id) { string requestingUser = User.FindFirstValue(ClaimTypes.NameIdentifier); Tag tagToDelete = await _context.Tags.FindAsync(id); if (tagToDelete.UserId != requestingUser) { return(BadRequest()); } List <Map> allUserMaps = Utilities.GetMapGallery(tagToDelete.UserId, "", _context); foreach (Map map in allUserMaps) { if (map.ActiveTags.Any(x => x.TagID == tagToDelete.TagID)) { int tagRelationID = map.ActiveTags.FirstOrDefault(x => x.TagID == tagToDelete.TagID).TagRelationID; TagRelation tagRelation = await _context.TagRelations.FindAsync(tagRelationID); _context.TagRelations.Remove(tagRelation); } } _context.Tags.Remove(tagToDelete); _context.SaveChanges(); return(NoContent()); }
/// <summary> /// Method to create tag /// </summary> /// <param name=""></param> public bool Create(List <ITagsDTO> listOfTags, int questionId) { using (var context = new BufferOverflowDBEntities()) { foreach (var tags in listOfTags) { var isExist = context.Tags.SingleOrDefault(t => t.Tag == tags.Tag); if (isExist == null) { Tags tagEntity = new Tags(); EntityConverter.FillEntityFromDTO(tags, tagEntity); isExist = context.Tags.Add(tagEntity); context.SaveChanges(); } TagRelation tagRelationEntity = context.TagRelation.SingleOrDefault(t => t.TagId == isExist.Id && t.QuestionId == questionId); if (tagRelationEntity == null) { tagRelationEntity = new TagRelation(); tagRelationEntity.QuestionId = questionId; tagRelationEntity.TagId = isExist.Id; context.TagRelation.Add(tagRelationEntity); context.SaveChanges(); } } return(true); } }
public ActionResult DeleteConfirmed(int id) { TagRelation tagRelation = db.TagRelations.Find(id); db.TagRelations.Remove(tagRelation); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "TagRelationID,TagID,PostID")] TagRelation tagRelation) { if (ModelState.IsValid) { db.Entry(tagRelation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PostID = new SelectList(db.Posts, "PostID", "Claim", tagRelation.PostID); ViewBag.TagID = new SelectList(db.Tags, "TagID", "Name", tagRelation.TagID); return(View(tagRelation)); }
internal static void SetTagRelation(TagRelation tagRelation) { if (tagRelation == null) { return; } SafeProcedure.ExecuteNonQuery( Database.GetDatabase(D4DDefine.DBInstanceName), "dbo.TagRelation_SetRelation", tagRelation.TagId, tagRelation.ObjectId, (int)tagRelation.ObjectType, tagRelation.AddUserID); }
// GET: TagRelations/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TagRelation tagRelation = db.TagRelations.Find(id); if (tagRelation == null) { return(HttpNotFound()); } return(View(tagRelation)); }
public async Task <IActionResult> DeleteTagRelation(int id) { string requestingUser = User.FindFirstValue(ClaimTypes.NameIdentifier); TagRelation tagRelation = await _context.TagRelations.FindAsync(id); if (tagRelation.UserId != requestingUser) { return(BadRequest()); } _context.TagRelations.Remove(tagRelation); _context.SaveChanges(); return(NoContent()); }
// GET: TagRelations/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TagRelation tagRelation = db.TagRelations.Find(id); if (tagRelation == null) { return(HttpNotFound()); } ViewBag.PostID = new SelectList(db.Posts, "PostID", "Claim", tagRelation.PostID); ViewBag.TagID = new SelectList(db.Tags, "TagID", "Name", tagRelation.TagID); return(View(tagRelation)); }
internal static TagRelation GetTagRelation(int tagId, int objectId, int objectType) { TagRelation tag = new TagRelation(); SafeProcedure.ExecuteAndMapRecords( Database.GetDatabase(D4DDefine.DBInstanceName), "dbo.TagRelation_Get", delegate(IRecord record) { tag.Id = record.GetInt32OrDefault(0, 0); tag.TagId = record.GetInt32OrDefault(1, 0); tag.ObjectId = record.GetInt32OrDefault(2, 0); tag.ObjectType = (ObjectTypeDefine)(record.GetInt32OrDefault(3, 0)); tag.AddUserID = record.GetInt32OrDefault(4, 0); tag.AddDate = record.GetDateTime(5); }, tagId, objectId, objectType); return(tag); }
internal static List <TagRelation> GetTagRelationByTagId(int tagId) { List <TagRelation> list = new List <TagRelation>(); SafeProcedure.ExecuteAndMapRecords( Database.GetDatabase(D4DDefine.DBInstanceName), "dbo.TagRelation_GetByTagId", delegate(IRecord record) { TagRelation tag = new TagRelation(); tag.Id = record.GetInt32OrDefault(0, 0); tag.TagId = record.GetInt32OrDefault(1, 0); tag.ObjectId = record.GetInt32OrDefault(2, 0); tag.ObjectType = (ObjectTypeDefine)(record.GetInt32OrDefault(3, 0)); tag.AddUserID = record.GetInt32OrDefault(4, 0); tag.AddDate = record.GetDateTime(5); list.Add(tag); }, tagId); return(list); }
public async Task <ActionResult <TagRelation> > PostTagRelation([FromBody] TagRelation relation) { relation.UserId = User.FindFirstValue(ClaimTypes.NameIdentifier); Map map = await _context.Maps.FindAsync(relation.MapID); Tag tag = await _context.Tags.FindAsync(relation.TagID); if (map is null || map.UserId != relation.UserId || tag.UserId != relation.UserId || tag is null) { return(BadRequest()); } relation.MapName = map.MapName; relation.TagName = tag.Name; await _context.AddAsync(relation); await _context.SaveChangesAsync(); return(relation); }
private void attach_TagRelations1(TagRelation entity) { this.SendPropertyChanging(); entity.Tag1 = this; }
private void detach_TagRelations1(TagRelation entity) { this.SendPropertyChanging(); entity.Tag1 = null; }
public void SetTagRelation(TagRelation tagRelation) { TagsDao.SetTagRelation(tagRelation); }
partial void DeleteTagRelation(TagRelation instance);
partial void UpdateTagRelation(TagRelation instance);
partial void InsertTagRelation(TagRelation instance);