Exemplo n.º 1
0
        public async Task<ActionResult> Save(DraftEditModel model)
        {
            model.EntryMode = EntryMode.SaveDraft;
            TryValidateModel(model);

            if (!ModelState.IsValid)
            {
                using (var parser = new MarkdownParser())
                {
                    model.Html = parser.Transform(model.Body);
                    return View("Edit", model);
                }
            }

            var draft = await _draftDbCommand.FindAsync(model.Id) ?? Draft.NewDraft(LogonUser, model.ItemType);
            Mapper.Map(model, draft);

            draft.LastModifiedDateTime = DateTime.Now;
            await _draftDbCommand.SaveAsync(draft);
            return RedirectToAction("Index", "Draft");
        }
Exemplo n.º 2
0
        public async Task<ActionResult> Publish(DraftEditModel model)
        {
            ModelState.Clear();

            model.EntryMode = EntryMode.PublishItem;
            TryValidateModel(model);

            if (!ModelState.IsValid)
            {
                using (var parser = new MarkdownParser())
                {
                    model.Html = parser.Transform(model.Body);
                    return View("Edit", model);
                }
            }

            var draft = await _draftDbCommand.FindAsync(model.Id, LogonUser) ?? Draft.NewDraft(LogonUser, model.ItemType);
            Mapper.Map(model, draft);

            var item = draft.ToItem();

            item.PublishSince = model.PublishSince;
            item.PublishUntil = model.PublishUntil;

            await _itemDbCommand.SaveAsync(item);
            await _draftDbCommand.DeleteAsync(draft.Id, LogonUser);

            return RedirectToAction("Index", "Item");
        }
Exemplo n.º 3
0
        public async Task<JsonResult> AutoSave(DraftEditModel model)
        {
            var draft = Mapper.Map<Draft>(model);
            draft.Author = LogonUser;
            draft.LastModifiedDateTime = DateTime.Now;
            await _draftDbCommand.SaveAsync(draft);

            return Json(new { draft.Id, Url = Url.Action("Edit", "Draft", new { id = draft.Id }) });
        }