forked from wojilu/wojilu
/
PollController.cs
executable file
·96 lines (70 loc) · 2.66 KB
/
PollController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2010, www.wojilu.com. All rights reserved.
*/
using System;
using System.Collections.Generic;
using wojilu.Web.Mvc;
using wojilu.Web.Mvc.Attr;
using wojilu.Common.AppBase.Interface;
using wojilu.Apps.Content.Domain;
using wojilu.Apps.Content.Interface;
using wojilu.Apps.Content.Service;
using wojilu.Web.Controller.Poll.Utils;
using wojilu.Common.AppBase;
namespace wojilu.Web.Controller.Content.Admin.Section {
[App( typeof( ContentApp ) )]
public partial class PollController : ControllerBase, IPageSection {
public IContentPostService postService { get; set; }
public ContentPollService pollService { get; set; }
public PollController() {
postService = new ContentPostService();
pollService = new ContentPollService();
}
public List<IPageSettingLink> GetSettingLink( int sectionId ) {
List<IPageSettingLink> links = new List<IPageSettingLink>();
PageSettingLink lnk = new PageSettingLink();
lnk.Name = lang( "editSetting" );
lnk.Url = to( new SectionSettingController().Edit, sectionId );
links.Add( lnk );
return links;
}
public void SectionShow( int sectionId ) {
}
public void AdminSectionShow( int sectionId ) {
ContentPoll c = pollService.GetRecentPoll( ctx.app.Id, sectionId );
bindPollSection( sectionId, c );
}
public void List( int sectionId ) {
DataPage<ContentPost> list = postService.GetPageBySection( sectionId );
bindPostList( list );
}
public void Add( int sectionId ) {
target( Create, sectionId );
set( "optionCount", 5 );
editor( "Question", "", "80px" );
}
[HttpDelete, DbTransaction]
public void Delete( int id ) {
ContentPost post = postService.GetById( id, ctx.owner.Id );
if (post != null) {
postService.Delete( post );
}
echoRedirect( lang( "opok" ) );
}
[HttpPost, DbTransaction]
public void Create( int sectionId ) {
ContentPoll poll = new PollValidator<ContentPoll>().Validate( ctx );
if (errors.HasErrors) {
run( Add, sectionId );
return;
}
Result result = pollService.CreatePoll( sectionId, poll );
if (result.HasErrors) {
echo( result.ErrorsHtml );
return;
}
ContentPost post = postService.GetById( poll.TopicId, ctx.owner.Id );
echoToParentPart( lang( "opok" ) );
}
}
}