Exemplo n.º 1
0
        public ActionResult Create(EditorViewModel model)
        {
            string slug = model.Title.ToUrlSlug();

            EntryContract existintEntry = this.Services.EntryService.Get(client => client.Get(slug));
            if (existintEntry.IsNotNull())
            {
                this.ModelState.AddModelError("Title", "Lo siento, ya existe una publicación con el slug '{0}', por favor cambiar el título.".FormatWith(slug));
            }

            if (!this.ModelState.IsValid)
            {
                return this.View("Edit", model);
            }

            model.Slug = slug;
            return this.Save(model, true) ? this.RedirectToAction("Show", "Entry", new { id = slug }) : this.View("Edit", model) as ActionResult;
        }
Exemplo n.º 2
0
        private bool Save(EditorViewModel model, bool creating = false)
        {
            EntryContract entry = this.Services.Mapper.Map<EntryContract, EditorViewModel>(model);
            entry.Author = this.Services.User.Current.FriendlyName;
            if (creating)
            {
                entry.CreatedAt = DateTime.Now;
            }

            Response response = this.Services.EntryService.Get(client => client.Save(entry));
            if (!response.Success)
            {
                this.ModelState.AddModelError("Error", "Hubo un problema guardando la publicación.");
            }

            return response.Success;
        }
Exemplo n.º 3
0
        public ActionResult Edit(EditorViewModel model)
        {
            if (model.Slug.IsNullOrEmpty())
            {
                this.ModelState.AddModelError("Error", "The slug was not found, the entry was not updated.");
            }

            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            return this.Save(model) ? this.RedirectToAction("Show", "Entry", new { id = model.Slug }) : this.View("Edit", model) as ActionResult;
        }