public DownloadViewModel(VideoModel videoModel) { VideoModel = videoModel; DefaultStartDate = VideoModel.RequestedInPoint.HasValue ? VideoModel.RequestedInPoint.Value : VideoModel.Event.DisplayStartDate; DefaultEndDate = VideoModel.RequestedOutPoint.HasValue ? VideoModel.RequestedOutPoint.Value : VideoModel.Event.DisplayEndDate; var firstDay = videoModel.Event.DisplayStartDate.ToLocalTime(); var secondDay = videoModel.Event.DisplayStartDate.AddDays(1).ToLocalTime(); var startFirstSelected = DefaultStartDate.ToLocalTime().Date == firstDay.Date; var startSecondSelected = DefaultStartDate.ToLocalTime().Date == secondDay.Date; var endFirstSelected = DefaultEndDate.ToLocalTime().Date == firstDay.Date; var endSecondSelected = DefaultEndDate.ToLocalTime().Date == secondDay.Date || !endFirstSelected; StartDates = new List <SelectListItem>() { new SelectListItem() { Text = firstDay.ToString("d MMMM yyyy"), Value = firstDay.ToString("yyyy-MM-dd"), Selected = startFirstSelected }, new SelectListItem() { Text = secondDay.ToString("d MMMM yyyy"), Value = secondDay.ToString("yyyy-MM-dd"), Selected = startSecondSelected } }; EndDates = new List <SelectListItem>() { new SelectListItem() { Text = firstDay.ToString("d MMMM yyyy"), Value = firstDay.ToString("yyyy-MM-dd"), Selected = endFirstSelected }, new SelectListItem() { Text = secondDay.ToString("d MMMM yyyy"), Value = secondDay.ToString("yyyy-MM-dd"), Selected = endSecondSelected } }; }
public virtual string TransformText() { #line 4 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.tt" if (DbmsPlatform == "SQL Server") { #line default #line hidden this.Write("IF OBJECT_ID(N\'"); #line 1 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(ObjectView)); #line default #line hidden this.Write("\', N\'V\') IS NULL\r\n\tEXECUTE (\'CREATE VIEW "); #line 2 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(ObjectView)); #line default #line hidden this.Write(" AS SELECT NULL AS CREATE_OR_REPLACE\');\r\nGO\r\n\r\nALTER VIEW "); #line 5 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(ObjectView)); #line default #line hidden this.Write(" AS\r\n-- This code was generated by "); #line 6 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(TemplateName)); #line default #line hidden this.Write(" @ "); #line 6 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DateTime.Now.ToString())); #line default #line hidden this.Write("\r\n"); #line 7 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" string tEndDateCol = IsEndDateNext ? "t2." + DateColumn : string.Format("DATEADD(day, -1, t2.{0})", DateColumn); if (DbmsVersion > new Version(11, 0)) // SQL Server 2012 { #line default #line hidden this.Write("SELECT\r\n\t"); #line 14 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(SelectColumns.InsertLeft())); #line default #line hidden this.Write("\r\n\t"); #line 15 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DateColumn)); #line default #line hidden this.Write("\t\tAS "); #line 15 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(RangeStartDateColumn)); #line default #line hidden this.Write(",\r\n\tLEAD("); #line 16 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(tEndDateCol)); #line default #line hidden this.Write(", 1"); #line 16 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DefaultEndDate.IsNullString() ? "" : ", " + DefaultEndDate)); #line default #line hidden this.Write(") OVER (PARTITION BY "); #line 16 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(Key_Columns)); #line default #line hidden this.Write(" ORDER BY "); #line 16 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DateColumn)); #line default #line hidden this.Write(")\r\n\t\t\t\t\t\t\t\tAS "); #line 17 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(RangeEndDateColumn)); #line default #line hidden this.Write("\r\nFROM\r\n\t"); #line 19 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(SourceView)); #line default #line hidden this.Write("\tt2\r\n"); #line 20 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" } else // SQL Server 2008, 2005 { if (!DefaultEndDate.IsNullString()) { tEndDateCol = string.Format("ISNULL({0}, {1})", tEndDateCol, DefaultEndDate); } #line default #line hidden this.Write("WITH TR AS\r\n(\r\n\tSELECT\r\n\t\t*,\r\n\t\tROW_NUMBER() OVER (PARTITION BY "); #line 31 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(Key_Columns)); #line default #line hidden this.Write(" ORDER BY "); #line 31 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DateColumn)); #line default #line hidden this.Write(") AS ROW$NUMBER\r\n\tFROM\r\n\t\t"); #line 33 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(SourceView)); #line default #line hidden this.Write("\r\n)\r\nSELECT\r\n\t"); #line 36 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(SelectColumns.Select(c => "t1." + c).InsertLeft())); #line default #line hidden this.Write("\r\n\tt1."); #line 37 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DateColumn)); #line default #line hidden this.Write("\t\tAS "); #line 37 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(RangeStartDateColumn)); #line default #line hidden this.Write(",\r\n\t"); #line 38 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(tEndDateCol)); #line default #line hidden this.Write("\t\t\tAS "); #line 38 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(RangeEndDateColumn)); #line default #line hidden this.Write("\r\nFROM\r\n\tTR t1 LEFT OUTER JOIN\r\n\tTR t2 ON ("); #line 41 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" this.Write(this.ToStringHelper.ToStringWithCulture(String.Join(" AND ", KeyColumns.Select(k => string.Format(@"t1.{0} = t2.{0}", k))))); #line default #line hidden this.Write("\r\n\t\tAND t1.ROW$NUMBER + 1 = t2.ROW$NUMBER)\r\n"); #line 43 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.SqlServer.sql" } #line default #line hidden this.Write(@"; GO ---------------------------------------------------------------------------------------------------- -- -- Copyright 2013 Abel Cheng -- This source code is subject to terms and conditions of the Apache License, Version 2.0. -- See http://www.apache.org/licenses/LICENSE-2.0. -- All other rights reserved. -- You must not remove this notice, or any other, from this software. -- -- Original Author: Abel Cheng <*****@*****.**> -- Created Date: May 20, 2013, 12:00:44 AM -- Primary Host: http://t4sql.codeplex.com -- Change Log: -- Author Date Comment -- -- -- -- -- (Keep code clean) -- ---------------------------------------------------------------------------------------------------- "); this.Write("\r\n"); #line 9 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.tt" } else if (DbmsPlatform == "Oracle") { #line default #line hidden this.Write("CREATE OR REPLACE VIEW "); #line 1 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(ObjectView)); #line default #line hidden this.Write(" AS\r\nSELECT\r\n\t-- This code was generated by "); #line 3 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(TemplateName)); #line default #line hidden this.Write(" @ "); #line 3 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DateTime.Now.ToString())); #line default #line hidden this.Write("\r\n"); #line 4 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" string tEndDateCol = IsEndDateNext ? DateColumn : string.Format("({0} - 1)", DateColumn); #line default #line hidden this.Write("\t"); #line 7 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(SelectColumns.InsertLeft())); #line default #line hidden this.Write("\r\n\t"); #line 8 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DateColumn)); #line default #line hidden this.Write("\t\tAS "); #line 8 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(RangeStartDateColumn)); #line default #line hidden this.Write(",\r\n\tLEAD("); #line 9 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(tEndDateCol)); #line default #line hidden this.Write(", 1"); #line 9 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DefaultEndDate.IsNullString() ? "" : ", " + DefaultEndDate)); #line default #line hidden this.Write(") OVER (PARTITION BY "); #line 9 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(Key_Columns)); #line default #line hidden this.Write(" ORDER BY "); #line 9 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(DateColumn)); #line default #line hidden this.Write(")\r\n\t\t\t\t\t\t\t\tAS "); #line 10 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(RangeEndDateColumn)); #line default #line hidden this.Write("\r\nFROM\r\n\t"); #line 12 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.Oracle.sql" this.Write(this.ToStringHelper.ToStringWithCulture(SourceView)); #line default #line hidden this.Write(@" WITH READ ONLY; ---------------------------------------------------------------------------------------------------- -- -- Copyright 2013 Abel Cheng -- This source code is subject to terms and conditions of the Apache License, Version 2.0. -- See http://www.apache.org/licenses/LICENSE-2.0. -- All other rights reserved. -- You must not remove this notice, or any other, from this software. -- -- Original Author: Abel Cheng <*****@*****.**> -- Created Date: May 20, 2013, 12:00:44 AM -- Primary Host: http://t4sql.codeplex.com -- Change Log: -- Author Date Comment -- -- -- -- -- (Keep code clean) -- ---------------------------------------------------------------------------------------------------- "); this.Write("\r\n"); #line 15 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.tt" } else { Error("T4SQL.Date.VTimePointsToRanges is not implemented for " + DbmsPlatform); } #line default #line hidden #line 21 "E:\Projects\T4SQL\T4SQLTemplateLibrary\T4Templates\Date\VTimePointsToRanges.tt" /* * Before building the project or checking in code, if any included file changes, * you should re-transform the including template in the solution by: * * Right-click one or more files in Solution Explorer and then click Run Custom Tool. * Use this method to transform a selected set of templates. * or * Click Transform All Templates in the Solution Explorer toolbar. * This will transform all the templates in the Visual Studio solution. * or * Installed Visual Studio Visualization and Modeling SDK * http://archive.msdn.microsoft.com/vsvmsdk, * And setup all the templates transformed automatically: * http://msdn.microsoft.com/en-us/library/dd820620.aspx#Regenerating * http://msdn.microsoft.com/en-us/library/ee847423.aspx * http://msdn.microsoft.com/en-us/library/ff521399.aspx */ #line default #line hidden return(this.GenerationEnvironment.ToString()); }