{"id":563,"date":"2011-04-27T02:23:00","date_gmt":"2011-04-27T02:23:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2011\/04\/27\/webmatrix-series-1-how-to-create-visual-basic-websites-using-webmatrix\/"},"modified":"2024-07-05T12:39:54","modified_gmt":"2024-07-05T19:39:54","slug":"webmatrix-series-1-how-to-create-visual-basic-websites-using-webmatrix","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/webmatrix-series-1-how-to-create-visual-basic-websites-using-webmatrix\/","title":{"rendered":"WebMatrix Series #1: How to Create Visual Basic Websites Using WebMatrix"},"content":{"rendered":"<p><span style=\"font-size: small\">&nbsp;<\/span>&nbsp;<span style=\"font-size: small\">Microsoft WebMatrix is an exciting new product that makes the creation of custom ASP.NET Web sites possible without all the complexity of the full Visual Studio environment. WebMatrix supports web site development in both C# and Visual Basic. In this blog post, I will demonstrate how to create VB websites using Webmatrix.<\/span><\/p>\n<p><span style=\"font-size: small\"><i>Before you begin, you need to have the following settings configured on your machine:<\/i><\/span><\/p>\n<ul>\n<li><span style=\"font-size: small\"><i>Ensure that you are running a Windows XP SP3 or a later version of operating system.<\/i> <\/span><\/li>\n<li><span style=\"font-size: small\"><i>Ensure that you have the administrator rights for the machine, as in this walkthrough you will be required to make changes to the &ldquo;C:Program FilesMicrosoft WebMatrixtemplates&rdquo; folder.<\/i> <\/span><\/li>\n<li><span style=\"font-size: small\"><i>You need to have the WebMatrix application installed. For more information about how to install WebMatrix, see <\/i><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=205867\"><i><span style=\"text-decoration: underline\">Microsoft Web Platform Installer<\/span><\/i><\/a><i>.<\/i><i>&nbsp;<\/i> <\/span><\/li>\n<li><span style=\"font-size: small\"><i>Download the <\/i><a href=\"http:\/\/visualstudiomagazine.com\/articles\/2011\/03\/28\/wcovb_webmatrix.aspx\"><i><span style=\"text-decoration: underline\">code<\/span><\/i><\/a><i> containing the VB templates.<\/i> <\/span><\/li>\n<li><span style=\"font-size: small\"><i>You need to configure the Visual Basic templates in WebMatrix, because by default WebMatrix only has the C# templates configured. For more information about how to configure the Visual Basic templates, see <\/i><a href=\"http:\/\/visualstudiomagazine.com\/articles\/2011\/03\/28\/wcovb_webmatrix.aspx\"><i><span style=\"text-decoration: underline\">Surfacing the Visual Basic Templates in WebMatrix<\/span><\/i><\/a><i>.<\/i> <\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: small\">You can create the Visual Basic websites using WebMatrix in the four simple steps as follows:<\/span><\/p>\n<p><span style=\"font-size: small\"><b>Step 1: Select a Template <br \/>Step 2: Create a Website using the Calendar Visual Basic Template <br \/>Step 3: Edit and Modify the Website <br \/>Step 4: Understand and Customize the Code<\/b><\/span><\/p>\n<h3>Step 1: Select a Template<\/h3>\n<p><span style=\"font-size: small\">You can create a website using any of the templates that are available in WebMatrix, as per your preference. In this step, we will see which all different templates are available that can be used to create a new website. <\/span><\/p>\n<ol>\n<li><span style=\"font-size: small\">Launch the WebMatrix application. The Quick Start &ndash; Microsoft WebMatrix dialog box is displayed. <br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/6646.Select%20template%201.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/6646.Select20template201.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">Select the &ldquo;Site From Template&rdquo; option. The Site from Template page is displayed. <br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/5430.Select%20template%203.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/5430.Select20template203.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">The Site from Template page should display the following templates. These templates include pre-built pages, which you can modify and customize to create your own website. You can select any of the following templates to create your site: <\/span>\n<ul>\n<li><span style=\"font-size: small\"><b>Empty Site.<\/b> This template creates a new empty site. Use this template if none of the other templates suit your needs, if you want to import files from an existing site, or if you want to build your site&#8217;s functionality from scratch. <\/span><\/li>\n<li><span style=\"font-size: small\"><b>Starter Site.<\/b> This is a C# site template. This template gives you a site with a professionally designed layout and a user login system. <\/span><\/li>\n<li><span style=\"font-size: small\"><b>Bakery<\/b>. This is a C# site template. This template creates a site that includes a database of your products and ways to display them. It also includes an order-processing system. <\/span><\/li>\n<li><span style=\"font-size: small\"><b>Photo Gallery<\/b>. This is a C# site template. Use this template to create a site where you can upload and display images. The site includes a user login system. <\/span><\/li>\n<li><span style=\"font-size: small\"><b>Calendar<\/b>. This is a C# site template. This template creates a website where users can create and share personal calendars. If they want to share a calendar, they can choose which users they want to share the calendar with. <\/span><\/li>\n<li><span style=\"font-size: small\"><b>Starter Site VB.<\/b> This is a VB site template. This template has the same features as that of Starter Site template. <\/span><\/li>\n<li><span style=\"font-size: small\"><b>Bakery VB<\/b>. This is a VB site template. This template has the same features as that of Bakery template. <\/span><\/li>\n<li><span style=\"font-size: small\"><b>Photo Gallery VB<\/b>. This is a VB site template. This template has the same features as that of Photo Gallery template. <\/span><\/li>\n<li><span style=\"font-size: small\"><b>Calendar VB<\/b>. This is a VB site template. This template has the same features as that of Calendar template. <\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: small\">If the page does not display the VB templates, then refer to <a href=\"http:\/\/visualstudiomagazine.com\/articles\/2011\/03\/28\/wcovb_webmatrix.aspx\"><span style=\"text-decoration: underline\">Surfacing the Visual Basic Templates in WebMatrix<\/span><\/a>, to learn more about how to configure the VB templates. <\/span><\/li>\n<li><span style=\"font-size: small\">Select the &ldquo;Calendar VB&rdquo; template, and click &ldquo;OK&rdquo;. <\/span><\/li>\n<\/ol>\n<h3>Step 2: Create a Website Using the Calendar Visual Basic Template<\/h3>\n<p><span style=\"font-size: small\">In this step, we will see how to create a website from the selected Visual Basic template. Once the Calendar VB template is selected, a default website is created based on the Calendar VB template. WebMatrix displays it in the Site workspace.<br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/6683.Administrator%201.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/6683.Administrator201.gif\" border=\"0\" \/><\/a><\/span><\/p>\n<p><span style=\"font-size: small\">To view how your website will look on the Internet, click &ldquo;Run&rdquo;. The website opens in the default browser.<br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/2477.Website%201.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/2477.Website201.gif\" border=\"0\" \/><\/a><\/span><\/p>\n<h3>Step 3: Edit and Modify the Website<\/h3>\n<p>You have created the website using the VB template. Now you can, modify and customize the site as per your preference. In this step, we will see how to modify the website.<\/p>\n<ol>\n<li><span style=\"font-size: small\">To register to the website, click &ldquo;Register&rdquo;. The Account Creation page is displayed.<br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/8880.Website%202.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/8880.Website202.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">Enter a Display Name for your account.<\/span><\/li>\n<li><span style=\"font-size: small\">Specify an Email id that you will use to login to the website.<\/span><\/li>\n<li><span style=\"font-size: small\">Select a time zone for your account.<\/span><\/li>\n<li><span style=\"font-size: small\">Enter a Password that you will use to login to the website.<\/span><\/li>\n<li><span style=\"font-size: small\">Re-enter the password in the Confirm password box, and click &ldquo;Register&rdquo;. You will be logged into the website, and your personal calendar will be displayed. <br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/0118.Website%203.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/0118.Website203.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">To change the theme of the website, select either of the &ldquo;Dark&rdquo;, &ldquo;GreenHeader&rdquo;, or Purple options. If you select the &ldquo;Dark&rdquo; option, the theme of the website will change as the following:<br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/2352.Website%204.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/2352.Website204.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">To add an event, click the add event icon. <br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/2018.Add%20icon%202.gif\"><img decoding=\"async\" height=\"30\" width=\"82\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/2018.Add20icon202.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">The Add an event page is displayed. Enter the details of the event, and click &ldquo;Create&rdquo;. The event will get added to the calendar.<br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/0385.Add%20event%201.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/0385.Add20event201.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">To add a calendar to share it with other users, click &ldquo;My Calendar &ndash; Add&rdquo;. The Add a Calendar page is displayed. <br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/7701.Add%20Calendar.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/7701.Add20Calendar.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">Enter the details of the calendar, and click Create. The calendar gets added to the list. <\/span><\/li>\n<li><span style=\"font-size: small\">To share the newly added calendar, click on the new calendar in the list. The Calendar page is displayed.<br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/7571.Add%20Calendar%201.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/7571.Add20Calendar201.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">To share the calendar, click &ldquo;Share&rdquo;. The Manage Sharing for page is displayed.<br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/4786.Share%20Calendar.gif\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/4786.Share20Calendar.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<li><span style=\"font-size: small\">Enter the name of user you want to share the calendar with, select the permission level, and click &ldquo;Add&rdquo;. The calendar will be shared with the selected user.<\/span><\/li>\n<\/ol>\n<h3>Step 4: Understand and Customize the Code<\/h3>\n<p>In this step, we will see how to modify and customize some part of the code in order to add a couple of validations.<\/p>\n<h4>Validate whether a color is already used by the logged in user<\/h4>\n<p><span style=\"font-size: small\">By default, when we try to create a calendar with a color that has already been used, the template still allows us to create the new calendar for the used color. To avoid this let us modify the code to allow validation of the calendar color before creating a new calendar.<\/span><\/p>\n<ol>\n<li><span style=\"font-size: small\">Go to the WebMatrix application.<\/span><\/li>\n<li><span style=\"font-size: small\">Select &ldquo;Files&rdquo; from the left pane. <\/span><\/li>\n<li><span style=\"font-size: small\">Open the ColorHelper.vb page in the App-Code folder. The ColorHelper.vb page is displayed.<\/span><\/li>\n<li><span style=\"font-size: small\">To create a method that searches the database for the occurrence of the color, add the following code:<br \/><\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">&nbsp;<br \/>The color to check\n<br \/>&#8221;&#8217; whether color found or not<br \/>Public Shared Function IsColorAvailable(ByVal userId As Integer, ByVal Color As String) As Object <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return db.QuerySingle(&#8220;SELECT * from CalendarsUsers &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;WHERE UserId = @0 &#8221; &amp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;AND color = @1 &#8220;,&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userId, Color) <br \/>End Function <\/span><\/p>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\"><i>Note: This method takes the user id and the color as inputs to search in the database table containing the details of the calendars of different users. It checks for the occurrence of the color specified by the logged in user, and returns whether the color has been used for the given user earlier or not. This method is also called when the calendar details are being edited. It does not allow the user to change the color of existing calendar to another color which has been used earlier by the user. However, the color can be changed to a color that has not been used earlier.<\/i><\/span><\/li>\n<li><span style=\"font-size: small\">Let&rsquo;s use this method now to validate the color, while the user is adding or editing the calendar. Open the CalendarForm.vbhtml page from the &ldquo;ThemesDefaultPartials&rdquo; folder. The CalendarForm.vbhtml page is displayed.<\/span><\/li>\n<li><span style=\"font-size: small\">To create a validation of the color, and show an error if the validation fails, add the following code: <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">If NOT ColorHelper.IsColorAvailable(WebSecurity.CurrentUserId, _color) Is Nothing Then <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ModelState.AddError(&#8220;color&#8221;, &#8220;This color is already in use.&#8221;) <br \/>End If <\/span><\/p>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\"><i>Note: This method validates the occurrence of the color by calling the method you had created in the previous step. If the validation fails then the &ldquo;This color is already in use&rdquo; error is displayed.<\/i><\/span><\/li>\n<\/ol>\n<h4>Validate the Start time and End time details while entering the details to create a new Calendar Event.<\/h4>\n<p><span style=\"font-size: small\">By default, when we try to create a calendar event, the template allows us to select an end time of calendar event smaller than the start time, which is logically incorrect. To remove this let us modify the code to allow validation of the event start time and end time before creating a new calendar event.<\/span><\/p>\n<ol>\n<li><span style=\"font-size: small\">Open the EventForm.vbhtml page from the &ldquo;ThemesDefaultPartials&rdquo; folder. The EventForm.vbhtml page is displayed. <\/span><\/li>\n<li><span style=\"font-size: small\">Search through the code to locate the section where the start and end date\/time is getting validated.<\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">&#8216; Validate the start and end date\/times. <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">If (Not Date.TryParse(Page.StartDate &amp; &#8221; &#8221; &amp; Page.StartTime, start)) OrElse <br \/>&nbsp;&nbsp; (Not Date.TryParse(Page.StartDate &amp; &#8221; &#8221; &amp; Page.EndTime, [end])) Then <br \/>&nbsp;&nbsp;&nbsp; ModelState.AddFormError(&#8220;One of the date \/ time strings were unreadable.&#8221;) <br \/>End If <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\">To create the validation that will check whether the end time of the calendar event is greater than the start time, add the following code: <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">If start &gt; [end] Then <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ModelState.AddFormError(&#8220;End Time should be later than Start Time&#8221;) <br \/>End If <\/span><\/p>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\"><i>Note: This method checks whether the Start time of the calendar event is greater than the end time. If this condition holds true, the &ldquo;End Time should be later than the Start Time&rdquo; error is displayed.<\/i><\/span><\/li>\n<li><span style=\"font-size: small\">Similarly, you can modify and customize the other parts of the code as well. The folder structure of the template looks like the following:<br \/><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/35\/13\/0842.Folder.gif\"><img decoding=\"async\" height=\"324\" width=\"218\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/04\/0842.Folder.gif\" border=\"0\" \/><\/a><\/span><\/li>\n<\/ol>\n<h4>Understand the Calendar Class<\/h4>\n<p><span style=\"font-size: small\">The &ldquo;Calendar&rdquo; folder contains a set of pages that are used to perform various functionalities such as adding a calendar, changing the theme of a calendar, changing the view of the calendar, deleting and editing the calendar, and to display the information of the calendar. The following methods are created in the Calendar class of the Calendar.vb page in the &ldquo;App_Code&rdquo; folder. Review the following code for different methods:<\/span><\/p>\n<ul>\n<li><span style=\"font-size: small\"><b>Update Calendar Color<\/b> method: This method takes the user id, calendar id, and color as inputs to search for the relevant calendar and then allows the user to update the color of the calendar.<\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Sub UpdateCalendarColor(ByVal userId As Integer, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal calendarId As Integer, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal color As String) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Execute(&#8220;UPDATE CalendarsUsers SET Color = @0 WHERE CalendarId = @1 AND UserId = @2&#8221;, color, calendarId, userId) <br \/>End Sub <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\"><b>Update Calendar<\/b> method: This method takes the user id and calendar id as inputs to search for the relevant calendar and then allows the user to update the calendar. This method allows the user to change the Name and Id of the calendar. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Sub UpdateCalendar(ByVal userId As Integer, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal calendarId As Integer, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Optional ByVal calendarName As String = Nothing,&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Optional ByVal color As String = Nothing) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color = If(color, ColorHelper.GetRandomColor()) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; calendarName = If(calendarName, &#8220;Default&#8221;) <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216; We are editing a calendar <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Execute(&#8220;UPDATE Calendars SET Name = @0 WHERE Id = @1&#8221;, calendarName, calendarId) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UpdateCalendarColor(userId, calendarId, color) <br \/>End Sub <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\"><b>Create Calendar<\/b> method: This method takes the user id, calendar id, and color as inputs to create a new calendar. This method creates a new calendar and then adds the calendar id to the logged in user.<\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Function CreateCalendar(ByVal userId As Integer, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Optional ByVal calendarName As String = Nothing, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Optional ByVal color As String = Nothing) As Integer <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color = If(color, ColorHelper.GetRandomColor()) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; calendarName = If(calendarName, &#8220;Default&#8221;) <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216; Create a new calendar <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Execute(&#8220;INSERT INTO Calendars (Name, Creator, Guid) Values (@0, @1, @2)&#8221;, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; calendarName, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; userId, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GenerateUniqueId()) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim calendarId = Convert.ToInt32(db.GetLastInsertId()) <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216; Add the calendar id to CalendarUsers <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Execute(&#8220;INSERT INTO CalendarsUsers (CalendarId, UserId, Permissions, Color) VALUES (@0, @1, @2, @3)&#8221;, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; calendarId, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; userId, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Permission.Own, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return calendarId <br \/>End Function <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\"><b>Delete Calendar<\/b> method: This method takes calendar id as input to search for the relevant calendar and then deletes it. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Sub DeleteCalendar(ByVal calendarId As Integer) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Execute(&#8220;DELETE FROM Events WHERE CalendarId = @0&#8221;, calendarId) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Execute(&#8220;DELETE FROM CalendarsUsers WHERE CalendarId = @0&#8221;, calendarId) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Execute(&#8220;DELETE FROM Calendars WHERE Id = @0&#8221;, calendarId) <br \/>End Sub <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\"><b>Get User Calendar<\/b> method: This method gets the calendar information using the calendar user pair to search for the relevant information. It takes the user id and the calendar id as inputs and returns the relevant calendar. This method returns a null value if no calendar exists for the given details. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Function GetUserCalendar(ByVal userId As Integer, ByVal calendarId As Integer) As Object <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return db.QuerySingle(&#8220;SELECT c.Name, c.Creator, c.Guid, cu.* &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;FROM Calendars AS c &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;JOIN CalendarsUsers AS cu ON c.Id = cu.CalendarId &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;WHERE cu.UserId = @0 &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;AND cu.CalendarId = @1 &#8220;, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; userId, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; calendarId) <br \/>End Function <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Function GetCalendarGroups(ByVal userId As Integer) As Object <br \/>&#8216; I should maintain a cache of all of the calendars loaded on the page <br \/>&#8216; to reduce calendar queries \/ joins&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim calendars = Calendar.GetUserCalendars(userId) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim calendarGroups = ( From c In CType(calendars, IEnumerable(Of Object)) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group c By GroupKey = c.Permissions &gt;= CInt(Permission.Own) Into g = Group Order By GroupKey&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select New With { Key .Own = If(GroupKey, &#8220;Mine&#8221;, &#8220;Shared&#8221;), <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Key .Calendars = g.OrderBy(Function(c) c.Name)}).ToDictionary(Function(g) g.Own, Function(g) g.Calendars)&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Return calendarGroups <br \/>End Function <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Function GetCalendar(ByVal calendarId As Integer) As Object <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return db.QuerySingle(&#8220;SELECT * FROM Calendars WHERE Id = @0&#8221;, calendarId) <br \/>End Function <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Function GetCalendarByHash(ByVal calendarId As Integer, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal hash As String) As Object&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return db.QuerySingle(&#8220;SELECT * FROM Calendars WHERE Id = @0 AND Guid = @1&#8221;, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; calendarId, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash) <br \/>End Function <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<h4>Understand the Event Class<\/h4>\n<p><span style=\"font-size: small\">The &ldquo;Event&rdquo; folder contains various pages that are used to perform various functionalities such as adding a calendar event, deleting a calendar event, downloading the calendar event in &ldquo;.ics&rdquo; format, editing a calendar event, and to display the information of a calendar event. The following methods are created in the Event class of the Event.vb page in the &ldquo;App_Code&rdquo; folder. Review the following code for different methods:<\/span><\/p>\n<ul>\n<li><span style=\"font-size: small\"><b>Add Event<\/b> method: This method takes the user id, calendar id, event name, event description, event location, start date, and end date as inputs to create a new calendar event. This method can create an event only if it starts and ends on the same day. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Function AddEvent(ByVal userId As Integer, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal calendarId As Integer,&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ByVal name As String, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal description As String, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal location As String, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal utcStart As Date, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal utcEnd As Date, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Optional ByVal allDay As Boolean = False) As Integer <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Query(&#8220;INSERT INTO Events &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;(OrganizerId, CalendarId, Name, Description, Location, AllDay, Start, [End]) &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Values (@0, @1, @2, @3, @4, @5, @6, @7) &#8220;,&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userId, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; calendarId, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; description, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; location, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; allDay, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; utcStart, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; utcEnd) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return Convert.ToInt32(db.GetLastInsertId()) <br \/>End Function <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\"><b>Delete Event<\/b> method: This method takes user id and event id as inputs to search for the relevant calendar event and then deletes it. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Sub DeleteEvent(ByVal eventId As Integer)&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Execute(&#8220;DELETE FROM EVENTS WHERE Id = @0&#8221;, eventId) <br \/>End Sub <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\"><b>Get Information of User &ndash; Event <\/b>method: This method gets the calendar event and calendar information using the user &#8211; event pair to search for the relevant information. It takes the user id and the event id as inputs and returns the relevant calendar events. This method returns a null value if no event exists for the given details. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 98.15%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 117.49%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 79px;color: black;font-size: 9pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Function GetUserEvent(ByVal userId As Integer, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal eventId As Integer) As Object <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Return db.QuerySingle( &#8220;SELECT e.*, c.Name AS CalendarName, c.Id AS CalendarId, cu.Color, cu.Permissions &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;FROM EVENTS AS e &#8221; &amp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;JOIN Calendars AS c ON e.CalendarID = c.Id &#8221; &amp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;JOIN CalendarsUsers AS cu ON c.Id = cu.CalendarId &#8221; &amp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;WHERE cu.UserId = @0 AND e.Id = @1 &#8220;, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; userId,&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eventId) <br \/>End Function <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">Public Shared Function GetCalendarEvents(ByVal calendarId As Integer) As Object <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db = UserHelper.DatabaseInstance <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return db.Query(&#8220;SELECT * FROM Events WHERE CalendarId = @0&#8221;, calendarId) <br \/><\/span><span style=\"font-family: 'Courier New';color: black;font-size: 8.5pt\">End Function <\/span><\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<h4>Understand the Themes folder<\/h4>\n<p><span style=\"font-size: small\">The &ldquo;Themes&rdquo; folder contains various default templates themes for the calendar. These template themes contain different predefined layouts, sections, and styles. The user can select any of the following themes to be applied it to their calendars: <\/span><\/p>\n<ul>\n<li><span style=\"font-size: small\">Dark<\/span><\/li>\n<li><span style=\"font-size: small\">Default<\/span><\/li>\n<li><span style=\"font-size: small\">Green Header<\/span><\/li>\n<li><span style=\"font-size: small\">Purple<\/span><\/li>\n<\/ul>\n<h3>Summary<\/h3>\n<p><span style=\"font-size: small\">That&rsquo;s it! You have now successfully created your first website based on the Visual Basic templates using Microsoft WebMatrix. In our next post, we will see how to publish the website for the others to see. <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;Microsoft WebMatrix is an exciting new product that makes the creation of custom ASP.NET Web sites possible without all the complexity of the full Visual Studio environment. WebMatrix supports web site development in both C# and Visual Basic. In this blog post, I will demonstrate how to create VB websites using Webmatrix. Before you begin, [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[195],"tags":[167,179],"class_list":["post-563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-basic","tag-vb2010","tag-webmatrix"],"acf":[],"blog_post_summary":"<p>&nbsp;&nbsp;Microsoft WebMatrix is an exciting new product that makes the creation of custom ASP.NET Web sites possible without all the complexity of the full Visual Studio environment. WebMatrix supports web site development in both C# and Visual Basic. In this blog post, I will demonstrate how to create VB websites using Webmatrix. Before you begin, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=563"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/563\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}