public ActionResult Create(gameViewModels item, HttpPostedFileBase idFile, HttpPostedFileBase idFilee) { if (ModelState.IsValid) { //upload de l'image // var path = Path.Combine(Server.MapPath("~/Content/img"), idFile.FileName); // idFile.SaveAs(path); // g.link_imgg = "img\\"+idFile.FileName; // g.link_img= "img\\" + idFilee.FileName; string uniqueName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(idFile.FileName); var uploadUrl = Server.MapPath("~/Content/img"); idFile.SaveAs(Path.Combine(uploadUrl, uniqueName)); string uniqueNamee = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(idFilee.FileName); var uploadUrll = Server.MapPath("~/Content/img"); idFilee.SaveAs(Path.Combine(uploadUrll, uniqueNamee)); item.link_imgg = "img\\" + uniqueName; item.link_img = "img\\" + uniqueNamee; item.DTYPE = "game"; item.date = DateTime.Now; item.rating = 0; // artSer.AddGames(g); game g = new game() { idArticle = item.idArticle, name = item.name, description = item.description, category = item.category, link_imgg = item.link_imgg, link_img = item.link_img, DTYPE = item.DTYPE, date = item.date, rating = item.rating, }; artSer.Add(g); return(RedirectToAction("Index")); } else { return(View()); } }
public async Task <IActionResult> Add([FromBody] Game game) { var result = await _gamesService.Add(game); return(Created("", result)); }