public Task<HttpResponseMessage> PostDocuments(int activityId, string activityMode)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            //Activity activity = _queryProcessor.Execute(new ActivityById(activityId));
            //if (activity == null)
            //{
            //    //string message = string.Format("Activity Id {0} not found", activityId);
            //    //return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message);
            //    throw new HttpResponseException(HttpStatusCode.InternalServerError);
            //}

            ActivityValues activityValues =
                _queryProcessor.Execute(new ActivityValuesByActivityIdAndMode(activityId, activityMode));

            if (activityValues == null)
            {
                //string message = string.Format("Activity Id {0} not found", activityId);
                //return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message);
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }

            var provider = new MultipartMemoryStreamProvider();

            var task = Request.Content.ReadAsMultipartAsync(provider).
                ContinueWith<HttpResponseMessage>(t =>
                {
                    if (t.IsFaulted || t.IsCanceled)
                    {
                        return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
                    }

                    //Activity activity = _queryProcessor.Execute(new ActivityById(activityId));
                    //if (activity == null)
                    //{
                    //    string message = string.Format("Activity Id {0} not found", activityId);
                    //    return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message);
                    //}

                    foreach (var item in provider.Contents)
                    {
                        string mimeType = item.Headers.ContentType.MediaType;
                        string filename = item.Headers.ContentDisposition.FileName;
                        char[] trimChars = { '"' };
                        filename = filename.Trim(trimChars).WithoutTrailingSlash();
                        string name = Path.GetFileNameWithoutExtension(filename);
                        string extension = Path.GetExtension(filename);

                        if (!String.IsNullOrEmpty(extension))
                        {
                            extension = extension.Substring(1);
                        }
                        else
                        {
                            // TBD - convert mime type to file extension
                            throw new HttpResponseException(HttpStatusCode.InternalServerError);
                        }

                        try
                        {
                            Stream stream = item.ReadAsStreamAsync().Result;
                            CreateActivityDocument activityDocumentCommand = null;

                            if (mimeType.Contains("image/"))
                            {
                                CreateImage createImageCommand = new CreateImage
                                {
                                    SourceStream = stream,
                                    Width = Int32.Parse(ConfigurationManager.AppSettings["ImageWidth"]),
                                    Height = Int32.Parse(ConfigurationManager.AppSettings["ImageHeight"]),
                                    Title = name,
                                    MimeType = mimeType,
                                    Name = name,
                                    Extension = extension,
                                    Size = stream.Length,
                                    Constrained = false
                                };

                                _createImage.Handle(createImageCommand);

                                activityDocumentCommand = new CreateActivityDocument(User)
                                {
                                    ActivityValuesId = activityValues.RevisionId,
                                    ImageId = createImageCommand.CreatedImage.Id,
                                    Mode = activityMode.AsEnum<ActivityMode>(),
                                    Title = name
                                };
                            }
                            else
                            {
                                CreateLoadableFile createLoadableFileCommand = new CreateLoadableFile
                                {
                                    SourceStream = stream,
                                    Name = name,
                                    Extension = extension,
                                    MimeType = mimeType,
                                    Title = name
                                };

                                _createLoadableFile.Handle(createLoadableFileCommand);

                                activityDocumentCommand = new CreateActivityDocument(User)
                                {
                                    ActivityValuesId = activityValues.RevisionId,
                                    FileId = createLoadableFileCommand.CreatedLoadableFile.Id,
                                    Mode = activityMode.AsEnum<ActivityMode>(),
                                    Title = name
                                };
                            }

                            _createActivityDocument.Handle(activityDocumentCommand);
                        }
                        catch (Exception ex)
                        {
                            Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message, "text/plain");
                        }

                    }

                    return Request.CreateResponse(HttpStatusCode.Created);
                });

            return task;
        }
        public HttpResponseMessage PostDocumentsValidateUploadFiletype(int activityid, [FromBody] string extension)
        {
            CreateImage createImageCommand = new CreateImage { Extension = extension };
            var createImageValidationResult = _validateImage.Validate(createImageCommand);
            if (!createImageValidationResult.IsValid)
            {
                CreateLoadableFile createLoadableFileCommand = new CreateLoadableFile { Extension = extension };
                var createLoadableFileValidationResult = _validateLoadableFile.Validate(createLoadableFileCommand);
                if (!createLoadableFileValidationResult.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest,
                        createLoadableFileValidationResult.Errors.First().ErrorMessage,
                        "text/plain");
                }
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        protected LoadableFile Seed(CreateLoadableFile command)
        {
            _createLoadableFile.Handle(command);
            _unitOfWork.SaveChanges();

            return command.CreatedLoadableFile;
        }