public BinaryDataResult FetchTemporaryFileData(Guid Id)
 {
     IHasBinaryData binaryData = new UploadFilePartialViewModel();
     binaryData.ID = Id;
     binaryData = TemporaryFileStrategy.Fetch(binaryData);
     return BinaryDataResult(binaryData.Data);
 }
        public ActionResult Upload(UploadFilePartialViewModel file)
        {
            UploadImageViewModel uploadImageViewModel = new UploadImageViewModel();
            uploadImageViewModel.UploadFilePartialViewModel = file;

            IListenToUser user = (IListenToUser)this.HttpContext.User;

            try
            {
                //So that files which arent valid arent persisted, we use the ImageFileValidationHelper..
                file = (UploadFilePartialViewModel)this.HandleTemporaryFile(file, new ImageFileValidationHelper());
            }
            catch (InvalidFileTypeException e)
            {
                LOG.Info("Attempt to upload invalid image",e);
            }

            ListenTo.Shared.DO.Image image = null;

            try
            {
                image = ImageManager.HandleUploadedImage(file.Data, user.UserCredentials);
                uploadImageViewModel.ImageUploadSuccesful = true;
                uploadImageViewModel.Image = image;
                LOG.Info("User " + this.User.Identity.Name + " uploaded an image with id " + image.ID);

            }
            catch (ValidationException e)
            {
                e.AddToModelState(ViewData.ModelState);
                LOG.Info("Attempt to upload invalid image", e);
            }

            return View(uploadImageViewModel);
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            UploadFilePartialViewModel model = null;

            Guid? id = ModelBinderHelpers.GetValueAndUpdateModelState<Guid?>(bindingContext, "FILEID");

            if (bindingContext.Model == null)
            {
                model = new UploadFilePartialViewModel();
            } else {
                model = (UploadFilePartialViewModel)bindingContext.Model;
            }

            if (!id.HasValue || id.Value == Guid.Empty)
            {
               id = Guid.NewGuid();
            }

            model.ID = id.Value;

            HttpPostedFileBase file = ListenTo.Web.Helpers.FileHelpers.GetFileFromRequest(controllerContext.HttpContext.Request, "POSTEDFILE");

            if (file != null && file.ContentLength > 0)
            {
                byte[] content = ListenTo.Web.Helpers.FileHelpers.GetContentFromHttpPostedFile(file);
                model.Data = content;
            }

            return model;
        }
 public ActionResult Add([Bind(Prefix = "Track")]Track track, UploadFilePartialViewModel file)
 {
     AddTrackViewModel addTrackViewModel = new AddTrackViewModel();
     addTrackViewModel.File = file;
     addTrackViewModel.Track = track;
     //We know that since this track is being added, it CANT have any persisted data!
     addTrackViewModel.HasPersistedTrackData = false;
     return ManageTrack(addTrackViewModel);
 }
        public ActionResult EditProfile(Guid id, FormCollection form)
        {
            UserProfile userProfile = UserProfileManager.GetByID(id);
            UpdateModel<UserProfile>(userProfile, "UserProfile");

            //This object represents a file the user has uploaded...
            UploadFilePartialViewModel file = new UploadFilePartialViewModel();
            UpdateModel<UploadFilePartialViewModel>(file);

            UploadImagePopupViewModel uploadImagePopupViewModel = new UploadImagePopupViewModel();
            UpdateModel<UploadImagePopupViewModel>(uploadImagePopupViewModel);

            if (uploadImagePopupViewModel.ImageMetaData != null)
            {
                userProfile.ProfileImage = uploadImagePopupViewModel.ImageMetaData;
            }

            //Here we can implement the specifics of handling our file...
            IListenToUser user = (IListenToUser)this.HttpContext.User;

            try
            {
                UserProfileManager.Save(userProfile, user.UserCredentials);
            }
            catch (ValidationException e)
            {
                e.AddToModelState(ViewData.ModelState, "UserProfile");
            }

            //If the model isnt valid
            if (!ViewData.ModelState.IsValid)
            {
                EditProfileViewModel editProfileViewModel = new EditProfileViewModel();
                editProfileViewModel.UserProfile = userProfile;
                editProfileViewModel.StyleSummaries = StyleManager.GetStyleSummaries(this.GetSite().ID);

                return View(editProfileViewModel);
            }

            return RedirectToWhoIs(userProfile);
        }
        public ActionResult Edit(Guid id, FormCollection formCollection)
        {
            AddTrackViewModel addTrackViewModel = new AddTrackViewModel();

            Track track = TrackManager.GetByID(id);
            UpdateModel<Track>(track,"Track");

            addTrackViewModel.Track = track;

            //This object represents a file the user has uploaded...
            UploadFilePartialViewModel file = new UploadFilePartialViewModel();
            UpdateModel<UploadFilePartialViewModel>(file);

            addTrackViewModel.File = file;

            return ManageTrack(addTrackViewModel);
        }