public IActionResult NewPersonnel([FromForm] Personnels personnels) { IActionResult response = BadRequest(new { messages = "Champ non completed" }); var File = personnels.file; try { if (File.Length > 0) { string path = _webHostEnvironment.WebRootPath + "\\uploads\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var fileName = File.FileName.Split("."); string name = fileName[0] + personnels.Name + "." + fileName[1]; using (var stream = System.IO.File.Create(path + name)) { File.CopyTo(stream); personnels.ImagePersonnel = File.FileName; stream.Flush(); } } response = Ok(new { success = "Personnel saves" }); } catch (Exception e) { response = BadRequest(new { Error = "Error during saving" }); Console.WriteLine("Erreur :" + e.Message); } Personnels.create(personnels); return(response); }