public async Task <IActionResult> PutProduit(Guid id, Produit produit) { if (id != produit.IdProd) { return(BadRequest()); } _context.Entry(produit).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProduitExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCategorie(Guid id, Categorie categorie) { if (id != categorie.IdCat) { return(BadRequest()); } _context.Entry(categorie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategorieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Upload(Guid id) { try { if (!Request.HasFormContentType) { throw new InvalidOperationException("Incorrect Content-Type: " + Request.ContentType); } var file = Request.Form.Files[0]; string path = "wwwroot/uploads/" + id; string fullPath = ""; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (file.Length > 0) { fullPath = Path.Combine(path, file.FileName); var stream = new FileStream(fullPath, FileMode.Create); await file.CopyToAsync(stream); stream.Close(); } _context.Images.Add(new Image() { ImageName = "Uploads/" + id + "/" + file.FileName, ProduitId = id }); await _context.SaveChangesAsync(); var prod = await _context.Produits.FindAsync(id); prod.FrontImg = prod.Images.FirstOrDefault <Image>().ImageName; _context.Entry(prod).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(_context)); } catch (Exception e) { return(Ok("fails execption" + e)); } }
public virtual void Update(T entity) { context.Entry <T>(entity).State = EntityState.Modified; }