public async Task <string> Post([FromForm] NewsContentModels mdl) { string result = "Something went wrong."; try { var file = Request.Form.Files[0]; string folderName = "Upload"; string webRootPath = _hostingEnvironment.WebRootPath; string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); string fullPath = Path.Combine(newPath, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } result = "Content uploaded successfully!!"; } return(result); } catch (System.Exception ex) { return(result + "\n" + ex.Message); } //return CreatedAtAction("GetUser", new { id = user.Id }, user); //return result; }
public async Task <int> SaveNewsContent(NewsContentModels mdl, IFormFileCollection files = null) { int result = 0; var data = DbClientFactory <PropertyDbClient> .Instance.GetAllProperty(_configuration["ConnectionStrings:DefaultConnection"]); return(await Task.Run(() => result)); }