public bool Save(string[] dna, bool isMutant) { bool saveSuccessfull = false; try { using (var context = new MELIDBEntities()) { StringBuilder sb = new StringBuilder(); int dimension = dna[0].Length; dna.ToList().ForEach(x => sb.Append(x)); persona.DNA = sb.ToString(); persona.ArrayLenght = dimension; persona.IsMutant = isMutant; context.Database.Connection.Open(); context.Personas.Add(persona); context.SaveChanges(); } } catch (Exception ex) { } finally { } return(saveSuccessfull); }
public IStatsServiceResponse GetStatistics() { try { using (var context = new MELIDBEntities()) { statsServiceResponse.count_mutant_dna = context.Personas.Select(x => x.IsMutant == true).Count(); statsServiceResponse.count_human_dna = context.Personas.Select(x => x.IsMutant == false).Count(); statsServiceResponse.ratio = statsServiceResponse.count_human_dna > 0 ? Math.Round(Convert.ToDecimal(statsServiceResponse.count_mutant_dna) / (Convert.ToDecimal(statsServiceResponse.count_mutant_dna) + Convert.ToDecimal(statsServiceResponse.count_human_dna)), 4):0; } } catch (Exception ex) { throw; } return(this.statsServiceResponse); }