public async Task <ActionResult <ResourceFile> > Post([FromForm] ResourceFileCreateDto resourceFileCreateDto) { if (resourceFileCreateDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_readCourseRepository.Exists(resourceFileCreateDto.CourseId)) { return(BadRequest("Cannot assigne file to an non-existing course.")); } this.HttpContext.Items.TryGetValue("UserId", out var userId); if (!_readCourseRepository.GetOwnerById(resourceFileCreateDto.CourseId).ToString().Equals(userId)) { return(BadRequest("You dont have owner privileges for this course.")); } ResourceFile resource = _mapper.DtoToEntity(resourceFileCreateDto); await _fileStorageService.UploadFile(resource.Id, resourceFileCreateDto.Resource.OpenReadStream(), resourceFileCreateDto.Resource.FileName); _writeResourceFileRepository.Create(resource); _writeResourceFileRepository.SaveChanges(); return(CreatedAtRoute("GetByResourceFileId", new { id = resource.Id }, resource)); }
public ActionResult <Course> Delete(Guid id) { if (!_readCourseRepository.Exists(id)) { return(NotFound()); } this.HttpContext.Items.TryGetValue("UserId", out var userId); if (!_readCourseRepository.GetOwnerById(id).ToString().Equals(userId)) { return(BadRequest("You dont have owner privileges for this course.")); } _writeCourseRepository.Delete(id); _writeCourseRepository.SaveChanges(); return(NoContent()); }