public async Task <ActionResult <StudyContent> > PostStudyContent(StudyContent studyContent) { _context.StudyDB.Add(studyContent); await _context.SaveChangesAsync(); return(CreatedAtAction("GetStudyContent", new { id = studyContent.GUID }, studyContent)); }
public async Task <ActionResult <StudyContent> > GetStudyContent(Guid id) { var studyContent = await _context.StudyDB.FindAsync(id); try { if (id == null) { return(BadRequest()); } string txtPath = Environment.CurrentDirectory + "/Data/" + id + ".json"; string studyFile = FileReader(txtPath); if (studyFile == null) { return(NotFound()); } StudyContent sc = JsonConvert.DeserializeObject <StudyContent>(studyFile); return(Ok(sc)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <IActionResult> PutStudyContent(Guid id, StudyContent studyContent) { if (id != studyContent.GUID) { return(BadRequest()); } _context.Entry(studyContent).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudyContentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }