Exemple #1
0
        public ActionResult RateName(string rating, string moleculeJson, string name)
        {
            bool isValid;
            int  score = -1;

            isValid = int.TryParse(rating, out score);

            if (isValid)
            {
                DbContextOptionsBuilder <ChemicalDbContext> options = new DbContextOptionsBuilder <ChemicalDbContext>();
                using (var chemicalDbContext = new ChemicalDbContext(options.Options))
                {
                    Molecule molecule = new Molecule()
                    {
                        Name = name, MoleculeJson = moleculeJson
                    };
                    chemicalDbContext.Add(molecule);
                    chemicalDbContext.SaveChanges();

                    Rating ratingObj = new Rating()
                    {
                        Score = Convert.ToInt32(rating), UserId = this.User.Identity.GetUserId(), MoleculeId = molecule.MoleculeId
                    };
                    chemicalDbContext.Add(ratingObj);
                    chemicalDbContext.SaveChanges();
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
        public string getName(ChemicalDbContext _context)
        {
            Dictionary <int, string> map = new Dictionary <int, string>();

            foreach (Node n in this.ParentChain.NodeList)
            {
                if (n.Divergent)
                {
                    map.Add(n.Position, _context.GetPrefixByLength(n.Branches[0].NodeList.Count()).Name);
                }
            }
            var identicalPairs = map.ToLookup(x => x.Value, x => x.Key).Where(x => x.Count() > 1);

            foreach (var item in identicalPairs)
            {
                string countPrefix = "";

                var keys = item.Aggregate("", (s, v) => s + ", " + v);
                switch (item.Count())
                {
                case 2:
                    countPrefix = "Di";
                    break;

                case 3:
                    countPrefix = "Tri";
                    break;

                case 4:
                    countPrefix = "Tetra";
                    break;
                }
                this.Name += keys + "-" + countPrefix + item.Key + "yl";
                this.Name.Substring(1);
            }
            foreach (var item in identicalPairs)
            {
                item.ToList().ForEach(q => { map.Remove(q); });
            }
            foreach (var item in map)
            {
                Name += item.Key + "-" + item.Value + "yl" + "-";
            }
            if (this.Name != null && Equals(this.Name[this.Name.Length - 1], "-"))
            {
                this.Name = this.Name.Substring(0, this.Name.Length - 2);
            }

            this.Name += _context.GetPrefixByLength(this.ParentChain.NodeList.Count).Name + "ane";
            if (Equals(this.Name.Substring(0, 1), ","))
            {
                this.Name = this.Name.Substring(1);
            }
            return(this.Name);
        }
        public IActionResult AdminPage()
        {
            DbContextOptionsBuilder <ChemicalDbContext> options = new DbContextOptionsBuilder <ChemicalDbContext>();

            using (var chemicalDbContext = new ChemicalDbContext(options.Options))
            {
                return(View("~/Views/Account/Admin.cshtml", new AdminViewModel()
                {
                    Molecules = chemicalDbContext.Molecules.ToDictionary(q => q.MoleculeId, q => q), Ratings = chemicalDbContext.Ratings.ToList()
                }));
            }
        }
 public MoleculeScanner(ChemicalDbContext context)
 {
     _context = context;
 }
Exemple #5
0
 public ChemicalController(ChemicalDbContext context)
 {
     _context = context;
     //scanner can access DB
     scanner = new MoleculeScanner(context);
 }