public String SaveScore()
        {
            int   score = int.Parse(Request.Form["rate"]);
            int   id    = int.Parse(Request.Form["id"]);
            goods g     = service.GetById(id);

            g.score = (g.score + score) / 2;
            service.Update(g);
            service.Commit();

            return(g.score.ToString());
        }
예제 #2
0
 public IActionResult Get([FromRoute] int id)
 {
     try
     {
         return(Ok(service.GetById(id)));
     }
     catch (Exception)
     {
         return(NotFound());
     }
 }
        public ActionResult SaveMyGood(GoodModels GM)
        {
            System.Diagnostics.Debug.WriteLine("------------------------------------   :    " + GM.goood.id_goods);


            service = new GoodService();

            swapperService     = new SwapperService();
            categoryService    = new CategoryService();
            subCategoryService = new SubCategoryService();


            int connectedSwapper = 1;

            swapper user = swapperService.Get(u => u.id_swapper == connectedSwapper);

            ViewBag.user = user;


            string   brand       = Request.Form["brand"];
            string   description = Request.Form["desc"];
            DateTime date        = DateTime.Now;
            int      validity    = 0;
            int      quantity    = int.Parse(Request.Form["quantity"]);
            string   label       = Request.Form["label"];

            int idGood = int.Parse(Request.Form["idGood"]);

            Accpted accepted = Accpted.no;

            int catId = int.Parse(Request.Form["cat"]);
            //category cat = categoryService.Get(c => c.id_category == catId);

            int subCatId = int.Parse(Request.Form["subCat"]);

            //subCategory subCat = subCategoryService.Get(sc => sc.id_subCategory == subCatId);

            GM.goood             = service.GetById(idGood);
            GM.goood.label       = label;
            GM.goood.brand       = brand;
            GM.goood.description = description;
            GM.goood.date        = date;
            GM.goood.validity    = validity;
            GM.goood.quantity    = quantity;
            GM.goood.accepted    = accepted;

            //subCat.category = cat;

            GM.goood.subCategoryID = subCatId;
            GM.goood.swapperID     = user.id_swapper;

            service.Update(GM.goood);
            service.Commit();



            if (Request.Files[0].ContentLength > 0)
            {
                byte[] file = null;
                using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
                {
                    file = binaryReader.ReadBytes(Request.Files[0].ContentLength);
                }


                Image img = this.byteArrayToImage(file);
                img = new Bitmap(img, new Size(180, 180));

                string path = "~/swapperImgs/" + GM.goood.id_goods + ".jpg";
                img.Save(Server.MapPath(path), System.Drawing.Imaging.ImageFormat.Jpeg);

                GM.goood.image = path;
                service.Update(GM.goood);
                service.Commit();
            }

            return(RedirectToAction("SearchMyGood"));
        }