Commits

Anton Afanasyev committed 00a1b2a

Removed instances of $safeprojectname$ crazyness. No reason to name yor variables "objThisType" and "colThisTypes" when you can have "item" and "items".
Include missing item class into the project and template
Furhter formatting changes (tabs to spaces)

  • Participants
  • Parent commits 846e6e8
  • Branches full-example

Comments (0)

Files changed (6)

File CS/Components/FeatureController.cs

 
 using System.Collections.Generic;
 using System.Xml;
+using DotNetNuke.Common.Utilities;
 using DotNetNuke.Entities.Modules;
 using DotNetNuke.Services.Search;
+using $NameSpace$$safeprojectname$.Data;
 
 namespace $NameSpace$$safeprojectname$.Components
 {
         /// <summary>
         /// Adds an object to the database
         /// </summary>
-        /// <param name="obj$safeprojectname$">The $safeprojectname$Info object</param>
-        public void AddItem($safeprojectname$Info obj$safeprojectname$)
+        /// <param name="item">The $safeprojectname$Info object</param>
+        public void AddItem($safeprojectname$Info item)
         {
-            if (obj$safeprojectname$.Content.Trim() != "")
+            if (item.Content.Trim() != "")
             {
-                DataProvider.Instance().AddItem(obj$safeprojectname$.ModuleId, obj$safeprojectname$.Content, obj$safeprojectname$.CreatedByUser);
+                DataProvider.Instance().AddItem(item.ModuleId, item.Content, item.CreatedByUser);
             }
         }
 
         /// <summary>
         /// Saves an object to the database
         /// </summary>
-        /// <param name="obj$safeprojectname$">The $safeprojectname$Info object</param>
-        public void UpdateItem($safeprojectname$Info obj$safeprojectname$)
+        /// <param name="item">The $safeprojectname$Info object</param>
+        public void UpdateItem($safeprojectname$Info item)
         {
-            if (obj$safeprojectname$.Content.Trim() != "")
+            if (item.Content.Trim() != "")
             {
-                DataProvider.Instance().UpdateItem(obj$safeprojectname$.ModuleId, obj$safeprojectname$.ItemId, obj$safeprojectname$.Content, obj$safeprojectname$.CreatedByUser);
+                DataProvider.Instance().UpdateItem(item.ModuleId, item.ItemId, item.Content, item.CreatedByUser);
             }
         }
 
         {
             SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();
 
-            List<$safeprojectname$Info> col$safeprojectname$s = Get$safeprojectname$s(ModInfo.ModuleID);
+            List<$safeprojectname$Info> items = GetItems(ModInfo.ModuleID);
 
-            foreach ($safeprojectname$Info obj$safeprojectname$ in col$safeprojectname$s)
+            foreach ($safeprojectname$Info item in items)
             {
-                SearchItemInfo SearchItem = new SearchItemInfo(ModInfo.ModuleTitle, obj$safeprojectname$.Content, obj$safeprojectname$.CreatedByUser, obj$safeprojectname$.CreatedDate, ModInfo.ModuleID, obj$safeprojectname$.ItemId.ToString(), obj$safeprojectname$.Content, "ItemId=" + obj$safeprojectname$.ItemId.ToString());
+                SearchItemInfo SearchItem = new SearchItemInfo(ModInfo.ModuleTitle, item.Content, item.CreatedByUser, item.CreatedDate, ModInfo.ModuleID, item.ItemId.ToString(), item.Content, "ItemId=" + item.ItemId.ToString());
                 SearchItemCollection.Add(SearchItem);
             }
 
         {
             string strXML = "";
 
-            List<$safeprojectname$Info> col$safeprojectname$s = Get$safeprojectname$s(ModuleID);
-            if (col$safeprojectname$s.Count != 0)
+            List<$safeprojectname$Info> items = GetItems(ModuleID);
+            if (items.Count != 0)
             {
                 strXML += "<$safeprojectname$s>";
 
-                foreach ($safeprojectname$Info obj$safeprojectname$ in col$safeprojectname$s)
+                foreach ($safeprojectname$Info item in items)
                 {
                     strXML += "<$safeprojectname$>";
-                    strXML += "<content>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(obj$safeprojectname$.Content) + "</content>";
+                    strXML += "<content>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(item.Content) + "</content>";
                     strXML += "</$safeprojectname$>";
                 }
                 strXML += "</$safeprojectname$s>";
         /// <param name="UserId">The Id of the user performing the import</param>
         public void ImportModule(int ModuleID, string Content, string Version, int UserID)
         {
-            XmlNode xml$safeprojectname$s = DotNetNuke.Common.Globals.GetContent(Content, "$safeprojectname$s");
-            foreach (XmlNode xml$safeprojectname$ in xml$safeprojectname$s.SelectNodes("$safeprojectname$"))
+            XmlNode xmlItems = DotNetNuke.Common.Globals.GetContent(Content, "$safeprojectname$s");
+            foreach (XmlNode xmlItem in xmlItems.SelectNodes("$safeprojectname$"))
             {
-                $safeprojectname$Info obj$safeprojectname$ = new $safeprojectname$Info();
-                obj$safeprojectname$.ModuleId = ModuleID;
-                obj$safeprojectname$.Content = xml$safeprojectname$.SelectSingleNode("content").InnerText;
-                obj$safeprojectname$.CreatedByUser = UserID;
-                Add$safeprojectname$(obj$safeprojectname$);
+                $safeprojectname$Info item = new $safeprojectname$Info();
+                item.ModuleId = ModuleID;
+                item.Content = xmlItem.SelectSingleNode("content").InnerText;
+                item.CreatedByUser = UserID;
+                AddItem(item);
             }
         }
 

File CS/Components/ModuleNameInfo.cs

         public string Content
         {
             get;
-            set
+            set;
         }
 
         public int CreatedByUser

File CS/DotNetNuke C# Compiled Module.vstemplate

 				<ProjectItem ReplaceParameters="true" TargetFileName="Edit.ascx.resx">Edit.ascx.resx</ProjectItem>
 				<ProjectItem ReplaceParameters="true" TargetFileName="Settings.ascx.resx">Settings.ascx.resx</ProjectItem>
 				<ProjectItem ReplaceParameters="true" TargetFileName="View.ascx.resx">View.ascx.resx</ProjectItem>
-        
+		
 			</Folder>
 
 			<Folder Name="BuildScripts" TargetFolderName="BuildScripts">
 
 			<Folder Name="Components" TargetFolderName="Components">
 				<ProjectItem ReplaceParameters="true" TargetFileName="FeatureController.cs">FeatureController.cs</ProjectItem>
+				<ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$Info.cs">ModuleNameInfo.cs</ProjectItem>
 			</Folder>
 
 			<Folder Name="Data" TargetFolderName="Data">
 			<ProjectItem ReplaceParameters="true" TargetFileName="License.txt">License.txt</ProjectItem>
 		</Project>
 	</TemplateContent>
-  <WizardExtension>
-    <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
-    <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
-  </WizardExtension>
-  <WizardData>
-    <packages repository="template">
-      <package id="MSBuildTasks" version="1.4.0.45" />
-    </packages>
-  </WizardData>
+	<WizardExtension>
+		<Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
+		<FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
+	</WizardExtension>
+	<WizardData>
+		<packages repository="template">
+			<package id="MSBuildTasks" version="1.4.0.45" />
+		</packages>
+	</WizardData>
 </VSTemplate>

File CS/Edit.ascx.cs

 using DotNetNuke.Services.Exceptions; 
 using DotNetNuke.Services.Localization;
 using DotNetNuke.Entities.Modules;
+using $NameSpace$$safeprojectname$.Components;
 
 namespace $NameSpace$$safeprojectname$
 {
     /// </summary>
     public partial class Edit : $safeprojectname$ModuleBase
     {
+        #region Private members
+        
+        private int ItemId = Null.NullInteger; 
+        
+        #endregion 
 
         #region Event Handlers
 
                     if (!Null.IsNull(ItemId))
                     { 
                         // get content 
-                        $safeprojectname$Controller obj$safeprojectname$s = new $safeprojectname$Controller(); 
-                        $safeprojectname$Info obj$safeprojectname$ = obj$safeprojectname$s.Get$safeprojectname$(ModuleId, ItemId); 
-                        if ((obj$safeprojectname$ != null))
+                        FeatureController controller = new FeatureController(); 
+                        $safeprojectname$Info item = controller.GetItem(ModuleId, ItemId); 
+                        if (item != null)
                         { 
-                            txtContent.Text = obj$safeprojectname$.Content; 
-                            ctlAudit.CreatedByUser = obj$safeprojectname$.CreatedByUserName; 
-                            ctlAudit.CreatedDate = obj$safeprojectname$.CreatedDate.ToString(); 
+                            txtContent.Text = item.Content; 
+                            ctlAudit.CreatedByUser = item.CreatedByUserName; 
+                            ctlAudit.CreatedDate = item.CreatedDate.ToString(); 
                         } 
                         else
                         { 
             } 
         } 
         
-        protected void cmdUpdate_Click(object sender, EventArgs e) 
-        { 
+        protected void cmdUpdate_Click(object sender, EventArgs e)
+        {
             try
-            { 
-                $safeprojectname$Controller obj$safeprojectname$s = new $safeprojectname$Controller(); 
-                
-                $safeprojectname$Info obj$safeprojectname$ = new $safeprojectname$Info(); 
-                
-                obj$safeprojectname$.ModuleId = ModuleId; 
-                obj$safeprojectname$.ItemId = ItemId; 
-                obj$safeprojectname$.Content = txtContent.Text; 
-                obj$safeprojectname$.CreatedByUser = this.UserId; 
+            {
+                FeatureController controller = new FeatureController();
+
+                $safeprojectname$Info item = new $safeprojectname$Info();
+
+                item.ModuleId = ModuleId;
+                item.ItemId = ItemId;
+                item.Content = txtContent.Text;
+                item.CreatedByUser = this.UserId;
                 
                 if (Null.IsNull(ItemId))
-                { 
-                    // add the content within the $safeprojectname$ table 
-                    obj$safeprojectname$s.Add$safeprojectname$(obj$safeprojectname$); 
-                } 
+                {
+                    // add the content within the $safeprojectname$ table
+                    controller.AddItem( item );
+                }
                 else
-                { 
-                    // update the content within the $safeprojectname$ table 
-                    obj$safeprojectname$s.Update$safeprojectname$(obj$safeprojectname$); 
-                } 
-                
-                // Redirect back to the portal home page 
-                Response.Redirect(Globals.NavigateURL(), true); 
-            } 
+                {
+                    // update the content within the $safeprojectname$ table
+                    controller.UpdateItem( item );
+                }
+
+                // Redirect back to the portal home page
+                Response.Redirect(Globals.NavigateURL(), true);
+            }
             catch (Exception exc)
-            { 
-                // Module failed to load 
-                Exceptions.ProcessModuleLoadException(this, exc); 
-            } 
-        } 
-        
+            {
+                // Module failed to load
+                Exceptions.ProcessModuleLoadException(this, exc);
+            }
+        }
+
         protected void cmdDelete_Click(object sender, EventArgs e) 
         { 
             try
                 if (!Null.IsNull(ItemId))
                 { 
                     
-                    $safeprojectname$Controller obj$safeprojectname$s = new $safeprojectname$Controller(); 
-                    obj$safeprojectname$s.Delete$safeprojectname$(ModuleId, ItemId); 
+                    FeatureController controller = new FeatureController(); 
+                    controller.DeleteItem(ModuleId, ItemId); 
                     
                 } 
                 

File CS/ModuleName.csproj

   </ItemGroup>
   <ItemGroup>
     <Compile Include="Components\FeatureController.cs" />
+    <Compile Include="Components\$safeprojectname$Info.cs" />
     <Compile Include="Data\DataProvider.cs" />
     <Content Include="Documentation\Documentation.css" />
     <Content Include="Documentation\Documentation.html" />

File CS/View.ascx.cs

 using DotNetNuke.Services.Localization;
 using DotNetNuke.Entities.Modules;
 using DotNetNuke.Entities.Modules.Actions;
+using $NameSpace$$safeprojectname$.Components;
 
 namespace $NameSpace$$safeprojectname$
 {
         {
             try
             {
-                $safeprojectname$Controller obj$safeprojectname$s = new $safeprojectname$Controller();
-                List<$safeprojectname$Info> col$safeprojectname$s;
+                FeatureController controller = new FeatureController();
 
-                // get the content from the $safeprojectname$ table 
-                col$safeprojectname$s = obj$safeprojectname$s.Get$safeprojectname$s(ModuleId);
+                List<$safeprojectname$Info> items = controller.GetItems(ModuleId);
 
-                if (col$safeprojectname$s.Count == 0)
+                if (items.Count == 0)
                 {
                     // add the content to the $safeprojectname$ table 
-                    $safeprojectname$Info obj$safeprojectname$ = new $safeprojectname$Info();
-                    obj$safeprojectname$.ModuleId = ModuleId;
-                    obj$safeprojectname$.Content = Localization.GetString("DefaultContent", LocalResourceFile);
-                    obj$safeprojectname$.CreatedByUser = this.UserId;
-                    obj$safeprojectname$s.Add$safeprojectname$(obj$safeprojectname$);
+                    $safeprojectname$Info item = new $safeprojectname$Info();
+                    item.ModuleId = ModuleId;
+                    item.Content = Localization.GetString("DefaultContent", LocalResourceFile);
+                    item.CreatedByUser = this.UserId;
+                    controller.AddItem(item);
                     // get the content from the $safeprojectname$ table 
-                    col$safeprojectname$s = obj$safeprojectname$s.Get$safeprojectname$s(ModuleId);
+                    items = controller.GetItems(ModuleId);
                 }
 
                 // bind the content to the repeater 
-                lstContent.DataSource = col$safeprojectname$s;
+                lstContent.DataSource = items;
                 lstContent.DataBind();
             }
             catch (Exception exc)
             get
             {
                 ModuleActionCollection Actions = new ModuleActionCollection();
-                Actions.Add(GetNextActionID(), Localization.GetString("EditModule", this.LocalResourceFile), "", "", "", EditUrl(), false, SecurityAccessLevel.Edit, true, false);
-                fixme
                 Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);
                 return Actions;
             }