public async Task <DomainExternalVideo> AddAsync(string projectId, DomainExternalVideo entity) { ProjectEntity project = await _projectRepository.GetAsync(projectId); if (project == null) { throw new NotFoundException(string.Format("Project {0} was not found", projectId)); } if (project.VideoType == (int)VideoType.Internal && !string.IsNullOrEmpty(project.OriginalVideoFileId) || project.VideoType == (int)VideoType.External && !string.IsNullOrEmpty(project.VideoSource)) { throw new ConflictException(string.Format("Project {0} already contains a video.", projectId)); } // updating project project.VideoType = (int)VideoType.External; project.VideoSource = entity.VideoUri; project.VideoSourceProductName = entity.ProductName; project.Modified = DateTime.UtcNow; await _projectRepository.SetVideoAsync(project.Id, project.VideoType, project.VideoSource, project.VideoSourceProductName); return(_mapper.Map <ProjectEntity, DomainExternalVideo>(project)); }
public async Task <HttpResponseMessage> Post(string id, ExternalVideoModel model) { // Get project entity await GetProjectAsync(id); DomainExternalVideo externalVideo = await _externalVideoService.AddAsync(id, model); var result = new ExternalVideo { ProductName = externalVideo.ProductName, VideoUri = externalVideo.VideoUri, AcsNamespace = _settings.AcsNamespace }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, result); return(response); }
// GET api/projects/{id}/external public async Task <HttpResponseMessage> Get(string id) { // Get project await GetProjectAsync(id); // Get DomainExternalVideo externalVideo = await _externalVideoService.GetAsync(id); if (externalVideo == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ResponseMessages.ResourceNotFound)); } var result = new ExternalVideo { ProductName = externalVideo.ProductName, VideoUri = externalVideo.VideoUri, AcsNamespace = _settings.AcsNamespace }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); }