public async Task <int> AddRelationship(int TemplateId, GNGene Gene, GNContact userContact) { LogUtil.LogMethod(logger, MethodBase.GetCurrentMethod()); int result = 0; return(await Task.Factory.StartNew <int>(() => { var tx = db.Database.BeginTransaction(); result = db.Database.ExecuteSqlCommand( "INSERT INTO [gn].[GNTemplateGenes]([GNTemplateId],[GeneCode],[GNGeneId],[CreatedBy],[CreatedDateTime]) " + "VALUES(@templateId, @geneCode, @geneId, @CreatedBy, @CreateDateTime)", new SqlParameter("@templateId", TemplateId), new SqlParameter("@geneCode", Gene.GeneCode), new SqlParameter("@geneId", Gene.Id), new SqlParameter("@CreatedBy", userContact.AspNetUserId), new SqlParameter("@CreateDateTime", DateTime.Now)); tx.Commit(); return result; })); //bool auditResult = new GNCloudNoSQLService().LogEvent(userContact, Guid.Parse(leftSampleId), this.ENTITY, "N/A", "INSERT_RELATIONSHIP"); //auditResult = new GNCloudNoSQLService().LogEvent(userContact, Guid.Parse(rigthSampleId), this.ENTITY, "N/A", "INSERT_RELATIONSHIP"); }
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 })); }