public IActionResult Update(ContentUploadVM ContentUploadVM, IFormFile file) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (file != null) { using (Stream stream = file.OpenReadStream()) { using (BinaryReader br = new BinaryReader(stream)) { var fileContent = br.ReadBytes((int)file.Length); ContentUploadVM.Image = SaveFileHelper.SaveFileToDisk(_env, fileContent, file.FileName, file.ContentType); } } } Content _sliderDb = _contentRepository.GetSingle(ContentUploadVM.Id); if (_sliderDb == null) { return(NotFound()); } Mapper.Map(ContentUploadVM, _sliderDb); _contentRepository.SaveChanges(); return(new NoContentResult()); }
public IActionResult Create(ContentUploadVM ContentUploadVM, IFormFile file) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (file != null) { using (Stream stream = file.OpenReadStream()) { using (BinaryReader br = new BinaryReader(stream)) { var fileContent = br.ReadBytes((int)file.Length); ContentUploadVM.Image = SaveFileHelper.SaveFileToDisk(_env, fileContent, file.FileName, file.ContentType); } } } Content _newContent = Mapper.Map <Content>(ContentUploadVM); _contentRepository.Add(_newContent); _contentRepository.SaveChanges(); CreatedAtRouteResult result = CreatedAtRoute("GetContent", new { controller = "Content", id = ContentUploadVM.Id }, ContentUploadVM); return(result); }