public async Task<HttpResponseMessage> PostUserImage()
        {
            // Check if the request contains multipart/form-data.
            if (Request.Content.IsMimeMultipartContent())
            {
                try
                {
                    #region Create ChangePicture ViewModel
                    int id = int.Parse(HttpContext.Current.Request.Form["UserId"]);
                    byte[] imageBytes = await GetImageBytesFromRequest();

                    ChangeUserPictureViewModel changeImage = new ChangeUserPictureViewModel()
                    {
                        UserId = id,
                        Picture = imageBytes
                    };
                    #endregion

                    CommandWorker.ChangeUserPicture(changeImage);

                    return Request.CreateResponse(HttpStatusCode.OK);
                }
                catch
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            //// Check if the request contains multipart/form-data.
            //if (Request.Content.IsMimeMultipartContent())
            //{
            //    User user;
            //    //var FormData = await Request.Content.ReadAsFormDataAsync();
            //    try
            //    {
            //        int id = int.Parse(HttpContext.Current.Request.Form["UserId"]);
            //        user = db.Users.Find(id);
            //    }
            //    catch {
            //        throw new HttpResponseException(HttpStatusCode.BadRequest);
            //    }
            //    var streamProvider = new MultipartMemoryStreamProvider();
            //    streamProvider = await Request.Content.ReadAsMultipartAsync(streamProvider);
            //    foreach (var item in streamProvider.Contents.Where(c => !string.IsNullOrEmpty(c.Headers.ContentDisposition.FileName)))
            //    {   
            //        Stream stPictureSource = new MemoryStream(await item.ReadAsByteArrayAsync());
            //        Stream stThumbSource = new MemoryStream(await item.ReadAsByteArrayAsync());
            //        // Resize for Picture
            //        MemoryStream stPictureDest = new MemoryStream();
            //        var pictureSettings = new ResizeSettings
            //        {
            //            MaxWidth = Constants.USER_PICTURE_MAXWIDTH,
            //            MaxHeight = Constants.USER_PICTURE_MAXHEIGHT,
            //            Format = Constants.USER_PICTURE_FORMAT,
            //            Mode = FitMode.Crop
            //        };
            //        ImageBuilder.Current.Build(stPictureSource, stPictureDest, pictureSettings);
            //        // Resize for ThumbNail
            //        MemoryStream stThumbDest = new MemoryStream();
            //        var thumbSettings = new ResizeSettings
            //        {
            //            MaxWidth = Constants.USER_THUMB_MAXWIDTH,
            //            MaxHeight = Constants.USER_THUMB_MAXHEIGHT,
            //            Format = Constants.USER_THUMB_FORMAT,
            //            Mode = FitMode.Crop
            //        };
            //        ImageBuilder.Current.Build(stThumbSource, stThumbDest, thumbSettings);

            //        user.Picture = "data:image/gif;base64," + Convert.ToBase64String(stPictureDest.ToArray());
            //        user.Thumb = "data:image/gif;base64," + Convert.ToBase64String(stThumbDest.ToArray());
            //    }
            //    await db.SaveChangesAsync();
            //    return Request.CreateResponse(HttpStatusCode.OK);
            //}
            //else{
            //    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            //}
        }
 public void ChangeUserPicture(ChangeUserPictureViewModel model)
 {
     Guid userId = database.IdMaps.GetAggregateId<User>(model.UserId);
     bus.Send(new ChangeUserPictureCommand(userId, model.Picture));
 }