Exemple #1
0
        public ActionResult AddProducts([Bind(Include = "Id,ProductId")] BestSelling bestSelling)
        {
            if (ModelState.IsValid)
            {
                db.BestSellings.Add(bestSelling);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", bestSelling.ProductId);
            return(View(bestSelling));
        }
Exemple #2
0
 public ActionResult AddProduct(int id)
 {
     try
     {
         BestSelling bs = new BestSelling()
         {
             ProductId = id
         };
         db.BestSellings.Add(bs);
         db.SaveChanges();
         return(Content("OK"));
     }
     catch (Exception ex)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
 }
        public static List <BestSelling> getBestSellingProduct()
        {
            List <BestSelling> list    = new List <BestSelling>();
            SqlConnection      connect = DBConnection.getInstance();

            connect.Open();
            SqlCommand    command = new SqlCommand(getBestSelling, connect);
            SqlDataReader rdr     = command.ExecuteReader();

            while (rdr.Read())
            {
                Int32       productId = rdr.GetInt32(0);
                Int32       selledNum = rdr.GetInt32(1);
                BestSelling obj       = new BestSelling(productId, selledNum);
                list.Add(obj);
            }
            connect.Close();
            return(list);
        }