【发布时间】:2017-10-05 04:28:09
【问题描述】:
我正在将我的一个网站从 WebForms 升级到 MVC Core。你能给我一些关于如何创建他们的数据库的建议吗?下面是来自Rabbit Bikes Products 页面后面的.VB 文件的一些示例代码。这很混乱,因为他们的很多产品都有两个或多个价格。
For Each prod As Product In myProducts
'Beginning Layout
temp &= "<article class=""dbItem""><figure class=""left dbImage"">"
temp &= "<img src=""" & prod.ImagePath & """ alt=""" & prod.Name & """ title=""" & prod.Name & """ style=""width: 100%;"" class=""pull-left img-rounded""></figure>"
temp &= "<h2>" & prod.Name & "</h2>"
temp &= "<div class="" scroller""><p>" & prod.Description & "</p></div>"
If Not prod.Description.Contains("shuttle") And Not prod.Name = "Trail Pass" Then
temp &= "<h3 style=""text-transform: uppercase;"">Call to reserve yours today!</h3>"
Else
temp &= "<h3 style=""text-transform: uppercase;"">Call to purchase one today!</h3>"
End If
temp &= "<br /><div style=""text-align: center;"">"
If prod.Description.Contains("shuttle") Or prod.Description.Contains("frequent rider") Then
temp &= "<span class=""oSnap"">One Person:</span> " & prod.TwoHrPrice.ToString("c") & "<br/>"
temp &= "<span class=""oSnap"">2 or More <abbr title=""people"">ppl.</abbr>:</span> " & prod.FourHrPrice.ToString("c") & "</p>"
End If
If prod.TwoHrPrice = 0 And Not prod.Description.Contains("shuttle") Then
temp &= "<p>Free with purchase!</p>"
End If
If prod.FourHrPrice <> 0 And Not prod.Description.Contains("shuttle") And Not prod.Description.Contains("frequent rider") Then
temp &= "<p><span class=""oSnap"">Half Day Price:</span> " & prod.FourHrPrice.ToString("c") & "<br/>"
End If
If prod.OneDayPrice <> 0 And Not prod.Description.Contains("shuttle") Then
temp &= "<span class=""oSnap"">One Day Price:</span> " & prod.OneDayPrice.ToString("c") & "<br/>"
End If
If prod.TwoDayPrice <> 0 And Not prod.Description.Contains("shuttle") Then
temp &= "<span class=""oSnap"">Two Day Price:</span> " & prod.TwoDayPrice.ToString("c") & "<br/>"
End If
If prod.WeekPrice <> 0 And Not prod.Description.Contains("shuttle") Then
temp &= "<span class=""oSnap"">Week Price:</span> " & prod.WeekPrice.ToString("c") & "</p>"
End If
'End Layout
temp &= "</div></article>"
Next
自从切换到 ASP.NET Core 1.1 和 Entity Framework 以来,我一直试图弄清楚如何检查每个项目的价格数量并适当地标记它们。我尝试使用数组,但它们不起作用,因为实体框架模型类中的每个变量类型都连接到 SQL Server 数据类型。我不想使用一堆 if/else 语句来计算与每个产品相关联的价格并再次适当地标记它们。我的产品类与带有实体框架和 CSS 的 ASP.NET MVC 中的产品类没有什么不同。
public class Product
{
public int ID { get; set; }
public string Image { get; set; }
[Display(Name = "Product Name")]
public string Name { get; set; }
public string Description { get; set; }
public string PriceLabels { get; set; }
public decimal Prices { get; set; }
//Add a third table to hold price information?
//public int? PriceTableID { get; set; }
public int? CategoryID { get; set; }
[Display(Name = "Category Name")]
public virtual Category Category { get; set; }
}
如果您对此问题有任何见解,我将不胜感激。
【问题讨论】:
标签: c# sql-server asp.net-mvc entity-framework asp.net-core