Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            TagRelation tagRelation = db.TagRelations.Find(id);

            db.TagRelations.Remove(tagRelation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
 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));
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        // 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));
        }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
        // 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));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
	private void attach_TagRelations1(TagRelation entity)
	{
		this.SendPropertyChanging();
		entity.Tag1 = this;
	}
Exemplo n.º 13
0
	private void detach_TagRelations1(TagRelation entity)
	{
		this.SendPropertyChanging();
		entity.Tag1 = null;
	}
Exemplo n.º 14
0
 public void SetTagRelation(TagRelation tagRelation)
 {
     TagsDao.SetTagRelation(tagRelation);
 }
Exemplo n.º 15
0
 partial void DeleteTagRelation(TagRelation instance);
Exemplo n.º 16
0
 partial void UpdateTagRelation(TagRelation instance);
Exemplo n.º 17
0
 partial void InsertTagRelation(TagRelation instance);