I am upgrading one of my sites from WebForms to MVC Core. Would you please give me some advice on how to create their database? Here is some example code from the .VB file behind the Rabbit Bikes Products page. It is VERY messy because a lot of their products have two or more prices.
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
Since switching to ASP.NET Core 1.1 and the Entity Framework, I've been trying to figure out how to check the number of prices for each item and labeling them appropriately. I tried using arrays, but they won't work because each variable type in an Entity Framework Model class is connected to a SQL Server data type. I don't want to use a bunch of if/else statements to count how many prices are associated with each product and label them appropriately again. My Product class isn't that different from the one in ASP.NET MVC with Entity Framework and CSS.
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; } }
I would appreciate any insight you might have about this issue.