/// <summary>
 /// Remover funciona assim:
 ///  Temos de obter a referencia para o registo e 
 ///  indicar que queremos remover com aquela mesma referencia.
 /// 
 /// </summary>
 private async void RemoveAssociationBetweenTagAndIssue(TagModel tagModel, int id)
 {
     var reg = await Context.IssueTagSet.Where(item => item.IssueId == id && item.TagName.Equals(tagModel.Name)).FirstAsync();
     Context.IssueTagSet.Remove(reg);
 }
        public async Task<HttpResponseMessage> AssociationBetweenTagAndIssue(string projectName, int id, [FromBody] string tag)
        {
            if (tag == null)
            {
                //lidar com erro
            }

            //verificar se tag está associada com Projecto ao qual o issue pertence
            var tagModel = new TagModel {Name = tag};
            if (! await IsTagRelatedToProject(projectName, tagModel))
            {
                return TagNotRelatedToProjectError("tag");
            }

            HttpResponseMessage response = null;
            //caso contrario, associar/remover conforme o HTTP method
            if (Request.Method.Equals(HttpMethod.Post))
            {
                //cria associação entre ambas
                AssociationBetweenTagAndIssue(tagModel, id);
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else if (Request.Method.Equals(HttpMethod.Delete))
            {
                //elemina a associação
                RemoveAssociationBetweenTagAndIssue(tagModel, id);
                //if the resource is immediately removed, the server should return a 200 code
                response = Request.CreateResponse(HttpStatusCode.OK);
            }

            //gravar alterações
            await Context.SaveChangesAsync();
            return response;
        }
 private void AssociationBetweenTagAndIssue(TagModel tagModel, int elementIndex)
 {
     Context.IssueTagSet.Add(new IssueTagSetModel { IssueId = elementIndex, TagName = tagModel.Name });
 }
 private async Task<bool> IsTagRelatedToProject(string projectName, TagModel tagModel)
 {
     var isTagPresent =
         await Context.ProjectTagSet.AnyAsync(r => r.ProjectName.Equals(projectName) && r.TagName.Equals(tagModel.Name));
     return isTagPresent;
 }