コード例 #1
0
 public NMRProblem(FormulaConfig formula)
 {
     H  = formula.H;
     C  = formula.C;
     N  = formula.N;
     O  = formula.O;
     F  = formula.F;
     Si = formula.Si;
     P  = formula.P;
     S  = formula.S;
     Cl = formula.Cl;
     Br = formula.Br;
     I  = formula.I;
 }
コード例 #2
0
        public IEnumerable <SpectraAnswer> RetrieveAnswer(FormulaConfig formula, float minIonPeak, float maxIonPeak)
        {
            if ((formula == null || !formula.IsValid()) &&
                (minIonPeak < 0 && maxIonPeak < 0 || minIonPeak > maxIonPeak))
            {
                return(null);
            }
            var ans = RetrieveAllAnswers();

            // nmr
            if (formula != null && formula.IsValid())
            {
                ans = ans.Where(p => p.NmrProblem != null && p.NmrProblem.IsEqual(formula));
            }
            // mass
            if (minIonPeak >= 0 && maxIonPeak >= 0)
            {
                ans = ans.Where(p =>
                                p.MassProblem != null && p.MassProblem.IonPeak <= maxIonPeak &&
                                p.MassProblem.IonPeak >= minIonPeak);
            }
            return(ans);
        }
コード例 #3
0
 public bool IsEqual(FormulaConfig formula)
 {
     return(H == formula.H && C == formula.C && N == formula.N && O == formula.O && F == formula.F &&
            Si == formula.Si && P == formula.P && S == formula.S && Cl == formula.Cl && Br == formula.Br &&
            I == formula.I);
 }
コード例 #4
0
        public async Task <SpectraAnswer> CreateAnswerAsync(string probDescription, string ansDescription,
                                                            List <string> probPics, List <string> ansPics, FormulaConfig formula, float ionPeak = -1)
        {
            if ((formula == null || !formula.IsValid()) && ionPeak < 0)
            {
                return(null);
            }
            var probPictures = probPics.Select(pic => new ProblemPicture(pic));
            var ansPictures  = ansPics.Select(pic => new AnswerPicture(pic));
            var answer       = new SpectraAnswer(probDescription, ansDescription);

            if (formula != null && formula.IsValid())
            {
                // NMR
                var nmrProb = new NMRProblem(formula);
                nmrProb.Answer = answer;
                await _context.NmrProblems.AddAsync(nmrProb);
            }

            if (ionPeak >= 0)
            {
                // Mass
                var massProb = new MassProblem(ionPeak);
                massProb.Answer = answer;
                await _context.MassProblems.AddAsync(massProb);
            }

            // add pictures to DB set
            foreach (var pic in ansPictures)
            {
                pic.SpectraAnswer = answer;
                await _context.AnswerPics.AddRangeAsync(pic);
            }

            foreach (var pic in probPictures)
            {
                pic.SpectraAnswer = answer;
                await _context.ProblemPics.AddAsync(pic);
            }

            await _context.SaveChangesAsync();

            return(RetrieveAnswerById(answer.Id));
        }
コード例 #5
0
        public async Task <SpectraAnswer> UpdateAnswerAsync(int id, string probDescription, string ansDescription,
                                                            List <string> probPics, List <string> ansPics,
                                                            float ionPeak = -1, FormulaConfig formula = null)
        {
            var ans = RetrieveAnswerById(id);

            if (ans == null || (ionPeak < 0 && (formula == null || !formula.IsValid())))
            {
                return(null);
            }

            ans.ProblemDescription = probDescription;
            ans.AnswerDescription  = ansDescription;
            var probPictures = probPics.Select(pic => new ProblemPicture(pic)
            {
                SpectraAnswer = ans
            }).ToList();
            var ansPictures = ansPics.Select(pic => new AnswerPicture(pic)
            {
                SpectraAnswer = ans
            }).ToList();

            // if not any ,then do nothing to old pictures
            if (ansPics.Any())
            {
                _context.AnswerPics.RemoveRange(ans.AnswerPictures);
                await _context.AnswerPics.AddRangeAsync(ansPictures);
            }

            if (probPics.Any())
            {
                _context.ProblemPics.RemoveRange(ans.ProblemPictures);
                await _context.ProblemPics.AddRangeAsync(probPictures);
            }


            // delete old nmr or mass problem
            if (ans.MassProblem != null)
            {
                _context.MassProblems.Remove(ans.MassProblem);
            }
            if (ans.NmrProblem != null)
            {
                _context.NmrProblems.Remove(ans.NmrProblem);
            }

            if (formula != null && formula.IsValid())
            {
                // nmr
                var nmrProblem = new NMRProblem(formula);
                nmrProblem.Answer = ans;
                await _context.NmrProblems.AddAsync(nmrProblem);
            }

            if (ionPeak >= 0)
            {
                // mass
                var massProblem = new MassProblem(ionPeak);
                massProblem.Answer = ans;
                await _context.MassProblems.AddAsync(massProblem);
            }


            var answerEntity = _context.SpectraAnswers.Attach(ans);

            answerEntity.State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(ans);
        }