public async Task <ActionResult> Edit(string id) { var draft = await _draftDbCommand.FindAsync(id, LogonUser); if (draft == null) { var item = await _itemDbCommand.FindAsync(id); if (item == null) { return(HttpNotFound()); } draft = item.ToDraft(LogonUser); await _draftDbCommand.SaveAsync(draft); } if (string.IsNullOrWhiteSpace(draft.Title)) { ViewBag.Title = "編集"; } else { ViewBag.Title = "編集: " + draft.Title; } var model = Mapper.Map <DraftEditModel>(draft); return(View(model)); }
public async Task <ActionResult> Item(string id) { var item = await _itemDbCommand.FindAsync(id); if (item == null) { return(HttpNotFound()); } var model = Mapper.Map <ItemViewModel>(item); model.CanEdit = (item.Author == LogonUser); ViewBag.Title = model.DisplayTitle; var comments = await _commentDbCommand.GetByItemAsync(item); foreach (var comment in comments) { var commentModel = Mapper.Map <CommentViewModel>(comment); if (comment.User == LogonUser) { commentModel.IsCommentAuthor = true; } model.Comments.Add(commentModel); } model.NewComment = (LogonUser == null) ? new CommentEditModel() : Mapper.Map <CommentEditModel>(item.NewComment(LogonUser)); return(View("Item", model)); }