public Model.Fajlovi Update(int id, FajloviInsertRequest request) { var entity = _context.FajloviPredmeta.Find(id); _mapper.Map(request, entity); entity.IsDeleted = false; _context.SaveChanges(); return(_mapper.Map <Model.Fajlovi>(entity)); }
public Model.Fajlovi Insert(FajloviInsertRequest request) { request.IsDeleted = false; var entity = _mapper.Map <Database.FajloviPredmeta>(request); _context.FajloviPredmeta.Add(entity); _context.SaveChanges(); return(_mapper.Map <Model.Fajlovi>(entity)); }
public IActionResult Upload([FromForm] FileProvider fileProvider) { try { var files = fileProvider.Files; //var testString = fileProvider.TestString; //var file = Request.Form.Files[0]; var file = fileProvider.Files[0]; FajloviInsertRequest request = new FajloviInsertRequest(); request.Naziv = fileProvider.Naziv; request.Opis = fileProvider.Opis; request.PredmetID = fileProvider.PredmetID; var folderName = Path.Combine("Resources", "Files"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fullPath = Path.Combine(pathToSave, fileName); var dbPath = Path.Combine(folderName, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } request.Url = fullPath; request.Ekstenzija = Path.GetExtension(fileName); _fajloviService.Insert(request); return(Ok(new { dbPath })); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, $"Internal server error: {ex}")); } }
public Model.Fajlovi Delete(int id, FajloviInsertRequest request) { return(_fajloviService.Delete(id, request)); }