forked from sachatrauwaen/OpenBlocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock_Edit.ascx.cs
More file actions
126 lines (119 loc) · 4.98 KB
/
Block_Edit.ascx.cs
File metadata and controls
126 lines (119 loc) · 4.98 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
' Copyright (c) 2014 Satrabel.be
' All rights reserved.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
*/
using System;
using DotNetNuke.Entities.Users;
using Satrabel.OpenBlocks.Block;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.UI.UserControls;
using DotNetNuke.Services.Localization;
using System.Web.UI.WebControls;
namespace Satrabel.OpenBlocks
{
public partial class Block_Edit : OpenBlocksModuleBase
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
//Implement your edit logic for your module
if (!Page.IsPostBack)
{
//get a list of users to assign the user to the Object
/*
ddlAssignedUser.DataSource = UserController.GetUsers(PortalId);
ddlAssignedUser.DataTextField = "Username";
ddlAssignedUser.DataValueField = "UserId";
ddlAssignedUser.DataBind();
*/
ddlCultureCode.DataSource = LocaleController.Instance.GetLocales(PortalId).Values;
ddlCultureCode.DataTextField = "NativeName";
ddlCultureCode.DataValueField = "Code";
ddlCultureCode.DataBind();
//check if we have an ID passed in via a querystring parameter, if so, load that item to edit.
//ItemId is defined in the ItemModuleBase.cs file
if (ItemId > 0)
{
var tc = new BlockController();
var t = tc.GetBlock(ItemId, PortalId);
if (t != null)
{
rblType.SelectedValue = t.BlockType.ToString();
txtName.Text = t.Name;
txtContentTxt.Text = t.Content;
((TextEditor)txtContentHtml).Text = t.Content;
ListItem li = ddlCultureCode.Items.FindByValue(t.CultureCode);
if (li != null)
{
li.Selected = true;
}
txtContentTxt.Visible = t.BlockType == 1;
txtContentHtml.Visible = t.BlockType == 2;
}
}
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
var t = new Satrabel.OpenBlocks.Block.Block();
var tc = new BlockController();
if (ItemId > 0)
{
t = tc.GetBlock(ItemId, PortalId);
t.LastModifiedByUserId = UserId;
t.LastModifiedOnDate = DateTime.Now;
//t.AssignedUserId = Convert.ToInt32(ddlAssignedUser.SelectedValue);
}
else
{
t = new Satrabel.OpenBlocks.Block.Block()
{
//AssignedUserId = Convert.ToInt32(ddlAssignedUser.SelectedValue),
CreatedByUserId = UserId,
CreatedOnDate = DateTime.Now,
};
}
t.Name = txtName.Text.Trim();
t.CultureCode = ddlCultureCode.SelectedIndex > 0 ? ddlCultureCode.SelectedValue : "";
t.BlockType = int.Parse(rblType.SelectedValue);
if (t.BlockType == 1)
t.Content = txtContentTxt.Text.Trim();
else if (t.BlockType == 2)
t.Content = ((TextEditor)txtContentHtml).Text;
t.LastModifiedOnDate = DateTime.Now;
t.LastModifiedByUserId = UserId;
t.PortalId = PortalId;
if (t.BlockId > 0)
{
tc.UpdateBlock(t);
}
else
{
tc.CreateBlock(t);
}
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL());
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL());
}
protected void rblType_SelectedIndexChanged(object sender, EventArgs e)
{
txtContentTxt.Visible = rblType.SelectedValue == "1";
txtContentHtml.Visible = rblType.SelectedValue == "2";
}
}
}