I'm new to Orchard development, C# and MVC, so forgive me if this is actually simple...
I used Orchard CMS in my profession so I understand the widgets, layer zones, content parts etc... however, I have tasked my self with improving one of the processes that is quite common, and I decided the best way would to be to create a module for this purpose.
The basic outline of the process using widgets would be as follows:
- Customer navigates to a page and is presented with three sections, Submit and View
The "submit" section is a widget which is a form (most likely a custom form) which posts to a controller, and submits that data to a DB, I think I have this figured out.. but to make sure I am going to use something like the following to do this:
[HttpPost] public ActionResult Index(string fName, string lName) { // var post values string fName = Request.Form["fName"]; string lName = Request.Form["lName"]; System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection(@"[CONNECTION STRING]"); System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "INSERT INTO Persons (FirstName, LastName) VALUES ('" + fName + "','" + lName +"')"; cmd.Connection = sqlConnection1; sqlConnection1.Open(); cmd.ExecuteNonQuery(); sqlConnection1.Close(); return View(); }
However, I am not sure this is the correct way to go about it, and I'm sure there is some better way I can do this, tutorials have recommended I use contentParts and contentPart records to submit data to the db however, this is only useful when submitting data from the admin side, this has to be able to be submitted from the front end by an end-user
- The second section is a table which would get a list of records from the database and display them to the user, however, for this I have no idea how to go about this at all, could anyone point me to a tutorial, example source code, or even code snippets where this is achieved?
It is worth noting, I have gone through the documentation for creating modules and widgets on Orchard's site, however, they are all updating the DB via the backend...
- Odatia