public static async Task <StartingMaterialDTO> GetStartingMaterialAsync(int reactionId) { StartingMaterialDTO result = new StartingMaterialDTO(); await Task.Run(() => { using (var db = new ChContext()) { var query = db.StartingMaterials.Where(r => r.ReactionID == reactionId).Include(m => m.MoleculeStatic).First(); result.Name = query.MoleculeStatic.Name; result.MoleculeCAS = query.MoleculeCAS; if (query.m.HasValue) { result.mValue = query.m.Value; } if (query.v.HasValue) { result.VValue = query.v.Value; } result.mp = query.MoleculeStatic.mp; result.bp = query.MoleculeStatic.bp; result.den = query.MoleculeStatic.d; } }); return(result); }
public async Task AddReaction(ReactionInfo reaction) { ReactionDTO reactionDTO = new ReactionDTO { Code = reaction.Code, Chemist = reaction.Chemist, Chiefchemist = reaction.Chiefchemist, Project = reaction.Project, Laboratory = reaction.Laboratory, StartDate = reaction.StartDate, ClosureDate = reaction.ClosureDate, PreviousStep = reaction.PreviousStep, Literature = reaction.Literature, IsSketch = reaction.IsSketch, ReactionImg = convertImg(reaction.ReactionImgPath), Procedure = reaction.Procedure, Yield = reaction.Yield, Observation = reaction.Observation }; StartingMaterialDTO smDTO = new StartingMaterialDTO { MoleculeCAS = reaction.StartingMaterial.CAS, ReactionName = reaction.Code, mValue = reaction.StartingMaterial.mValue, nValue = reaction.StartingMaterial.nValue, VValue = reaction.StartingMaterial.VValue, Location = reaction.StartingMaterial.Location }; List <ReagentDTO> reagentDTOs = new List <ReagentDTO>(); foreach (var item in reaction.Reagents) { reagentDTOs.Add(new ReagentDTO { MoleculeCAS = item.CAS, ReactionName = reaction.Code, Ratio = item.Ratio, Location = item.Location, mValue = item.mValue, VValue = item.VValue }); } List <SolventDTO> solventDTOs = new List <SolventDTO>(); foreach (var item in reaction.Solvents) { solventDTOs.Add(new SolventDTO { MoleculeCAS = item.CAS, ReactionName = reaction.Code, VValue = item.VValue, Location = item.Location }); } List <ProductDTO> productDTOs = new List <ProductDTO>(); foreach (var item in reaction.Products) { productDTOs.Add(new ProductDTO { ReactionName = reaction.Code, MW = item.mValue, Ratio = item.Ratio }); } List <byte[]> observationImgs = new List <byte[]>(); foreach (var item in reaction.ObservationImgPaths) { observationImgs.Add(convertImg(item)); } reactionDTO.StartingMaterial = smDTO; reactionDTO.Reagents = reagentDTOs; reactionDTO.Solvents = solventDTOs; reactionDTO.Products = productDTOs; reactionDTO.ObservationImgs = observationImgs; await DbAccess.AddReactionAsync(reactionDTO); }