public void AddGood(string name, string categoryname, int price, int quantity) { Goods good = new Goods(); good = FillData(good, name, categoryname, price, quantity); goodService.Add(mapper.Map <GoodDTO>(good)); }
public void Add([Required][FromBody] AddGoodDto dto) { _service.Add(dto); }
public ActionResult addGoods() { service = new GoodService(); swapperService = new SwapperService(); categoryService = new CategoryService(); subCategoryService = new SubCategoryService(); int connectedSwapper = 1; // connected swapper -identity 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"]; 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); goods newGood = new goods(); newGood.label = label; newGood.brand = brand; newGood.description = description; newGood.date = date; newGood.validity = validity; newGood.quantity = quantity; newGood.accepted = accepted; //subCat.category = cat; newGood.subCategoryID = subCatId; newGood.swapperID = user.id_swapper; service.Add(newGood); service.Commit(); if (Request.Files[0].ContentLength > 0) // on a ajouté une image pour le produit { 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/" + newGood.id_goods + ".jpg"; img.Save(Server.MapPath(path), System.Drawing.Imaging.ImageFormat.Jpeg); newGood.image = path; service.Update(newGood); service.Commit(); } return(RedirectToAction("SearchGood")); }