public async Task <ActionResult> RemoveGeneFromTemplate()
        {
            int resultCode = 2;
            //     auditResult = audit.LogEvent(UserContact, Guid.Parse(Request["leftSampleId"]), this.ENTITY, this.Request.UserHostAddress, "REMOVE_PEDIGREE");
            int            AssociationId = Int32.Parse(Request["relId"]);
            GNTemplateGene tempGene      = db.GNTemplateGenes.Where(a => a.Id == AssociationId).FirstOrDefault();

            if (tempGene != null)
            {
                auditResult = audit.LogEvent(UserContact, Guid.Empty, this.ENTITY, this.Request.UserHostAddress, "REMOVE_GENE_FROM_TEMPLATE " + tempGene.GNTemplateId + " : " + tempGene.GeneCode);
                int TemplateId = tempGene.GNTemplateId;
                int result     = await((TemplateService)entityService).RemoveGeneFromTemplate(AssociationId);
                return(RedirectToAction("Details", "Templates", new { id = TemplateId, resultCode = resultCode, geneCode = tempGene.GeneCode }));
            }

            //int result = await ((SampleService)entityService).RemoveRelationship(id, Guid.Parse(leftSampleId), Guid.Parse(rightSampleId));
            return(RedirectToAction("Index", "Templates"));
        }
        public async Task <ActionResult> AddGeneToTemplate()
        {
            auditResult = audit.LogEvent(UserContact, Guid.Empty, this.ENTITY, this.Request.UserHostAddress, "ADD_GENE_TO_TEMPLATE " + Request["GeneCode"].Trim().ToUpper());
            int    resultCode = 1;
            int    TemplateId = Int32.Parse(Request["Id"]);
            string GeneCode   = Request["GeneCode"].Trim().ToUpper();

            if (GeneCode == "")
            {
                resultCode = -3;
            }
            else
            {
                GNGene gene = db.GNGenes.Where(a => a.GeneCode.Equals(GeneCode)).FirstOrDefault();

                if (gene != null)
                {
                    GNTemplateGene tempGene = db.GNTemplateGenes.Where(a => a.GNTemplateId == TemplateId && a.GeneCode.Equals(GeneCode)).FirstOrDefault();
                    if (tempGene != null)
                    {
                        resultCode = -1;
                        //association template-gene already exists
                    }
                    else
                    {
                        //insert
                        int result = await((TemplateService)entityService).AddRelationship(TemplateId, gene, UserContact);
                    }
                }
                else
                {
                    resultCode = -2;
                }
            }

            //int result = await ((SampleService)entityService).RemoveRelationship(id, Guid.Parse(leftSampleId), Guid.Parse(rightSampleId));
            return(RedirectToAction("Details", "Templates", new { id = TemplateId, resultCode = resultCode, geneCode = GeneCode }));
        }