Esempio n. 1
0
        public ActionResult EditTemplate(string guid, RiverTemplateViewModel vm)
        {
            ValidateRiverTemplate(vm);

            if (!ModelState.IsValid)
            {
                var errors = this.ProduceAJAXErrorMessage(ModelState);
                return HttpDoc<EmptyHttpReponse>.PreconditionFailed(errors.ToJson()).ToJson();
            }

            // now that we are done with validation, get on with business

            var wall = RavenSession.Query<RiverWall>().Where(x => x.Guid == vm.RiverGuid).FirstOrDefault();

            //template of such guid doesn't exist
            if (wall == null)
                return HttpDoc<EmptyHttpReponse>.NotFound("Tabbed Rivers with Guid " + vm.RiverGuid + " does not exist").ToJson();
            else
            {
                wall.LastModified = Stamp.Time();
                wall.Template.FeedTemplate = vm.FeedTemplate;
                wall.Template.WallTemplate = vm.WallTemplate;
                wall.Template.LessCss.SetText(vm.LessCss);
                wall.Template.JavaScript.SetText(vm.JavaScript);
                wall.Template.CoffeeScript.SetText(vm.CoffeeScript);
                wall.Template.HtmlHeadInline = vm.HtmlHeadInline;
                wall.Template.HtmlBodyInline = vm.HtmlBodyInline;

                try
                {
                    RavenSession.Store(wall);
                    this.RavenSession.SaveChanges();

                    return HttpDoc<dynamic>.OK(new { Message = "hello world 2" }).ToJson();
                }
                catch (Exception ex)
                {
                    return HttpDoc<EmptyHttpReponse>.InternalServerError(ex.Message).ToJson();
                }
            }
        }
Esempio n. 2
0
        private void ValidateRiverTemplate(RiverTemplateViewModel vm)
        {
            //validate and validate some more
            var validator = new RiverTemplateViewModelValidator();
            ValidationResult results = validator.Validate(vm);
            results.AddToModelState(ModelState, string.Empty);

            try
            {
                var feedTemplate = DotLiquid.Template.Parse(vm.WallTemplate);
            }
            catch (DotLiquid.Exceptions.SyntaxException se)
            {
                this.PropertyValidationMessage("WallLiquidTemplate", se.Message);
            }

            try
            {
                var feedTemplate = DotLiquid.Template.Parse(vm.FeedTemplate);
            }
            catch (DotLiquid.Exceptions.SyntaxException se)
            {
                this.PropertyValidationMessage("FeedLiquidTemplate", se.Message);
            }
        }
Esempio n. 3
0
        public ActionResult EditTemplate(string guid)
        {
            var wall = RavenSession.Query<RiverWall>().Where(x => x.Guid == guid).FirstOrDefault();

            if (wall == null)
                return HttpNotFound();

            var vm = new RiverTemplateViewModel(wall);

            return View(vm);
        }