Example #1
0
        public async Task<HttpResponseMessage> Post(string id, ProjectVideoModel model)
        {
            // Check whether project with such id exists
            await GetProjectAsync(id);

            // Add video to that project
            var video = new DomainVideo
            {
                FileName = model.Video.Name,
                FileUri = model.Video.Uri,
                ContentType = model.Video.ContentType,
                FileLength = model.Video.Length
            };

            try
            {
                video = await _videoRepository.AddAsync(id, video);
            }
            catch (AggregateException aggregateException)
            {
                // Handle VideoFormatExceptions
                var errorsList = new StringBuilder(String.Format("{0}\n", aggregateException.Message));
                foreach (Exception exception in aggregateException.InnerExceptions)
                {
                    var videoFormatException = exception as VideoFormatException;
                    if (videoFormatException == null)
                    {
                        Trace.TraceError("Failed to add a video file: {0}", exception);
                        return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ResponseMessages.InternalServerError);
                    }

                    string errorMessage = GetExceptionDescription(videoFormatException.ParamType);
                    errorsList.AppendLine(errorMessage);
                    ModelState.AddModelError("Video", errorMessage);
                }

                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            var projectVideo = new ProjectVideo
            {
                Name = video.FileName,
                Uri = video.FileUri,
                ContentType = video.ContentType,
                Length = video.FileLength
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, projectVideo);
            response.SetLastModifiedDate(video.Modified);

            return response;
        }
Example #2
0
 // PUT api/projects/{id}/video/file
 public HttpResponseMessage Put(string id, ProjectVideoModel model)
 {
     return Request.CreateErrorResponse(HttpStatusCode.MethodNotAllowed, ResponseMessages.MethodNotAllowed);
 }