Exemplo n.º 1
0
        public bool RefreshThumb(string exerciseId, string videoId)
        {
            var exr = RavenSession.Load <Exercise>("exercises/" + exerciseId);

            Thumbnailer.GenerateThumbs(exr.Id, exr.VideoId);

            RavenSession.SaveChanges();

            return(true);
        }
Exemplo n.º 2
0
        public ActionResult Create(ExerciseViewModel postedModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(postedModel));
                }

                //this code could use some TLC

                var newExercise = new Exercise();

                string[] lines = postedModel.Categories.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                newExercise.Categories = new List <string>(lines.Where(x => !string.IsNullOrWhiteSpace(x)));


                if (!string.IsNullOrWhiteSpace(postedModel.VideoId))
                {
                    newExercise.VideoId = postedModel.VideoId.Trim();
                }

                Ownership.Assign(newExercise, this);

                if (this.ApplicationAdministrator)
                {
                    newExercise.Master = true;
                }
                newExercise.CreatedOn   = DateTime.Now;
                newExercise.Name        = postedModel.Name.Trim();
                newExercise.Description = postedModel.Description;

                RavenSession.Store(newExercise);
                RavenSession.SaveChanges();

                if (!string.IsNullOrWhiteSpace(postedModel.VideoId))
                {
                    var success = Thumbnailer.GenerateThumbs(newExercise.Id, newExercise.VideoId);
                    if (!success)
                    {
                        this.WarnUser("We couldn't generate a thumbnail image for this exercise.  The video id could be wrong or Vimeo may be not be " +
                                      "responding.  We'll try to generate the thumbnail again but it would be a good idea to double" +
                                      "check the video id. Sorry about that.");
                    }
                }

                HighFive("New exercise created ok.");

                return(RedirectToAction("List"));
            }
            catch
            {
                return(View(postedModel));
            }
        }
Exemplo n.º 3
0
        public ActionResult Index(string path)
        {
            var attachment = MvcApplication.Store.DatabaseCommands.GetAttachment(path);

            if ((path.Contains("largethumb") || path.Contains("smallthumb")) && attachment == null)
            {
                var split = path.Split(new[] { "/" }, StringSplitOptions.None);

                var attachmentPath = split[0];
                var id             = split[1];
                var exercise       = RavenSession.Load <Exercise>("exercises/" + id);

                if (exercise == null)
                {
                    exercise = RavenSession.Load <MasterExercise>("masterexercises/" + id);
                }

                var originalExerciseAttachment =
                    MvcApplication.Store.DatabaseCommands.GetAttachment(attachmentPath + "/" + exercise.OriginalExercise);

                if (originalExerciseAttachment != null)
                {
                    return(new FileStreamResult(originalExerciseAttachment.Data(), "image/jpeg"));
                }

                Thumbnailer.GenerateThumbs(exercise.Id, exercise.VideoId);

                attachment = MvcApplication.Store.DatabaseCommands.GetAttachment(path);
            }

            if (attachment == null)
            {
                var blankImagePath = Server.MapPath("/content/img/blank.png");
                return(new FilePathResult(blankImagePath, "image/png"));
            }

            return(new FileStreamResult(attachment.Data(), "image/jpeg"));
        }