public async Task <ActionResult <ModuleDTO> > PutModule(int id, ModuleDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } if (!id.Equals(model.Id)) { return(BadRequest("Differing Ids")); } var exist1 = await _crudService.AnyAsync <Course>(c => c.Id.Equals(model.CourseId)); if (!exist1) { return(NotFound("Cant find related id in VideoDTO")); } if (await _crudService.UpdateAsync <ModuleDTO, Module>(model)) { return(NoContent()); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to add the entity")); } return(BadRequest("Cannot update")); }
public async Task <ActionResult <DownloadDTO> > PostDownload(DownloadDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } var exist = await _crudService.AnyAsync <Course>(c => c.Id.Equals(model.CourseId)); var exist1 = await _crudService.AnyAsync <Module>(m => m.Id.Equals(model.ModuleId)); if (!exist && !exist1) { return(NotFound("Cant find related id in VideoDTO")); } var id = await _crudService.CreateAsync <DownloadDTO, Download>(model); if (id < 1) { return(BadRequest("Unable to add the entity")); } var Dto = await _crudService.GetSingleAsync <Download, DownloadDTO>(s => s.Id.Equals(id), true); if (Dto == null) { return(BadRequest("Cannot create entity")); } var uri = _linkGenerator.GetPathByAction("GetSingleDownload", "Downloads", new { id }); return(Created(uri, Dto)); } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Server Failure!")); } }
public async Task <ActionResult <CourseDTO> > PostCourse(CourseDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } var exist = await _crudService.AnyAsync <Instructor>(s => s.Id.Equals(model.InstructorId)); if (!exist) { return(NotFound("Cant find related id in CourseDTO")); } var id = await _crudService.CreateAsync <CourseDTO, Course>(model); if (id < 1) { return(BadRequest("Unable to add the entity")); } var dto = await _crudService.GetSingleAsync <Course, CourseDTO>(s => s.Id.Equals(id), true); if (dto == null) { return(BadRequest("Cannot create entity")); } var uri = _linkGenerator.GetPathByAction("GetSingleCourse", "Courses", new { id }); return(Created(uri, dto)); } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Server Failure!")); } }
public async Task <ActionResult <InstructorDTO> > DeleteInstructor(int id) { try { var exist = await _crudService.AnyAsync <Instructor>(s => s.Id.Equals(id)); if (!exist) { return(NotFound("Unable to find the related entity")); } if (await _crudService.DeleteAsync <Instructor>(i => i.Id.Equals(id))) { return(NoContent()); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to add the entity")); } return(BadRequest("Cannot delete this item!")); }