I have been working on a wizard interface on the application I am building. I am down to the last step/s, which unlike all the previous steps is all in one table.
To assist I have been reading and trying to emulate this tutorial I found as it looks like the approach I need for this specific step/s. http://www.binaryintellect.net/articles/9a5fe277-6e7e-43e5-8408-a28ff5be7801.aspx
I reasonably quickly realised there is some issues here I don't understand, and some of this looks out of date.
What I don't get. I have a model:
public class QuoteDetails { public int QuoteDetailsID { get; set; } public int QuoteID { get; set; } [Display(Name = "Distance in km")] public decimal Distance { get; set; } [Display(Name = "Allowed Hours")] public double AllowedHours { get; set; } [Display(Name = "Hourly Charge Rate")] [DataType(DataType.Currency)] public decimal HourlyCharge { get; set; } [Display(Name = "Calculated Cost")] [DataType(DataType.Currency)] public decimal CalculatedCost { get; set; } [Display(Name = "Margin to Apply")] public double Margin { get; set; } [Display(Name = "Quote Introduction")] public string QuoteIntroduction { get; set; } [Display(Name = "Quote Closing")] public string QuoteConclusion { get; set; } [Display(Name = "Quote Submit Date")] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:D}")] public DateTime QuoteDate { get; set; } public Quote Quote { get; set; } public ICollection<QuoteFollowUp> QuoteFollowUp { get; set; }
Using the examples in the tutorial it suggests breaking this out to View Models.
I haven't worked with view models before. All the other tutorials I have worked with work direct with data. I have seen them talked about and been content to know they are there, but without a specific need I thought I would avoid them...until now.
So I set up the view model for the first step:
using System.ComponentModel.DataAnnotations; namespace Eva804.ViewModel { public class SalesQuoteStep1 { [Required] public int QuoteID { get; set; } [Display(Name = "Distance in km")] public decimal Distance { get; set; } [Display(Name = "Allowed Hours")] public double AllowedHours { get; set; } } }
What I am finding somewhat confusing here is:
How does the view model know we are pointing to the Quote Details model?
I would have assumed a using statement is required. Why isn't it?
Then the tutorial suggests using session state to hold the data temporarily. This sounds like a good idea and looks like a good idea. However the tutorial examples use Session.etc. This is changed in Asp.Net core.
I found through readings how to set up the sessions within Asp.Net Core however I am now confused with the next step in the tutorial. From Tutorial:
private Customer GetCustomer() { if (Session["customer"] == null) { Session["customer"] = new Customer(); } return (Customer)Session["customer"]; }
Okay, so in ASP.Net Core we use
HttpContext.Session.SetString("SalesQuote", "quoteID");
As I understand it, and I may have this wrong, this initiates a session and gives a name SalesQuote and stores quoteID in it. Have I got this correct?
I am not sure how to go about checking if the session exists as in the tutorial?
Is there a better tutorial using a similar approach?
I have emboldened the questions as they are scattered in the post.
Thanks in advance