コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Degem degem = db.Degems.Find(id);

            db.Degems.Remove(degem);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "DegemId,DegemName,Color,BrandID,Quantity,VideoLink,ImagesLinks")] Degem degem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(degem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BrandID = new SelectList(db.Brands, "id", "BrandName", degem.BrandID);
     return(View(degem));
 }
コード例 #3
0
        public ActionResult Create([Bind(Include = "DegemId,DegemName,Color,BrandID,Quantity,VideoLink,ImageLink")] Degem degem)
        {
            if (ModelState.IsValid)
            {
                db.Degems.Add(degem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BrandID = new SelectList(db.Brands, "id", "BrandName", degem.BrandID);
            return(View(degem));
        }
コード例 #4
0
        // GET: Degems/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Degem degem = db.Degems.Find(id);

            if (degem == null)
            {
                return(HttpNotFound());
            }
            return(View(degem));
        }
コード例 #5
0
        // GET: Degems/Delete/5
        public ActionResult Delete(int?id)
        {
            if (!User.IsInRole("Admin"))
            {
                return(new HttpUnauthorizedResult("Unauthorized"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Degem degem = db.Degems.Find(id);

            if (degem == null)
            {
                return(HttpNotFound());
            }
            return(View(degem));
        }
コード例 #6
0
        // GET: Degems/Search
        public ActionResult algo()
        {
            var           bayesCLS = new BayesSimpleTextClassifier();                                                   //Naive Bayes object https://github.com/afonsof/BayesSharp
            var           degems   = db.Degems.Include(d => d.Brand);                                                   // take list of all cars
            List <string> goodCar  = db.TrainingDatas.Where(g => g.title.Equals("good")).Select(g => g.title).ToList(); //list of words for good car
            List <string> badCar   = db.TrainingDatas.Where(g => g.title.Equals("bad")).Select(g => g.title).ToList();  //list of words for bad car


            foreach (var good in goodCar)// trains the good part
            {
                bayesCLS.Train("good", good);
            }
            foreach (var bad in badCar)// trains the bad part
            {
                bayesCLS.Train("bad", bad);
            }
            var maxScore    = -1.0;        //save the computed score
            var favoriteCar = new Degem(); //save the bast car

            foreach (var car in degems)    // move on each car and check the score
            {
                //save the score
                var good = 0.0;
                var bad  = 0.0;
                foreach (var p in car.Comments)                        // move on each post and check the score
                {
                    var result = bayesCLS.Classify(p.ContentInfo);     //:)
                    if (result.ContainsKey("good"))
                    {                                                  //check if have any result
                        good += result["good"] / car.Comments.Count(); //if yes normelaize it and save it
                    }
                    if (result.ContainsKey("bad"))
                    {
                        bad += result["bad"] / car.Comments.Count();
                    }
                }
                if (good - bad > maxScore)//check the current car score
                {
                    maxScore    = good - bad;
                    favoriteCar = car;//if is max save it
                }
            }
            return(View("Details", favoriteCar));//return the bast car
        }
コード例 #7
0
        // GET: Degems/Edit/5
        public ActionResult Edit(int?id)
        {
            if (!User.IsInRole("Admin"))
            {
                return(new HttpUnauthorizedResult("Unauthorized"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Degem degem = db.Degems.Find(id);

            if (degem == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BrandID = new SelectList(db.Brands, "id", "BrandName", degem.BrandID);
            return(View(degem));
        }