public IActionResult Post(DnaClass dna) { try { DnaTestClass DnaTest = new DnaTestClass(dna); if (DnaTest.IsMutant()) { DnaPersit(ref DnaTest); return(Ok(DnaTest.DNA)); } else { DnaPersit(ref DnaTest); return(BadRequest(new ErrorEnvelopeClass { Error = DnaTest.Error })); } } catch (Exception ex) { return(BadRequest(new ErrorEnvelopeClass { Error = ex.Message })); } }
static void Main(string[] args) { DnaTestClass _test = new DnaTestClass(new string[] { "ATGCGA", "CAGTGC", "TTATGT", "AGAAGG", "CCCCTA", "TCACTG" }); //DnaTestClass _test = new DnaTestClass(new string[] { "ATGCG", "CAGTG", "TTATG", "AGAAG", "CCCCT" }); Console.WriteLine("-- ¿¿ es una cadena dna ?? --"); Console.WriteLine(_test.IsValid); Console.WriteLine("-- cadena dna --"); foreach (var item in _test.DNA) { Console.WriteLine(item.ToString()); } Console.WriteLine("-- ¿¿ es mutante ?? --"); Console.WriteLine(_test.IsMutant()); }
/// <summary> /// función de persistencia de cadenas DNA /// </summary> /// <param name="dnatest"></param> void DnaPersit(ref DnaTestClass dnatest) { try { // GUARDIANES if (_context.DNA.Count() >= _maxMutantDNADBContextCapacity) { throw new ApplicationException("NO SE PUEDEN ALMACENAR MÁS DNAS PARA ESTA SESIÓN"); } _context.DNA.Add(new DnaEntityClass { Signature = dnatest.DNASignature, IsMutant = dnatest.IsMutant() }); _context.SaveChanges(); } catch (Exception ex) { throw ex; } }