I have some experience with ASP.NET MVC, but since a couple of weeks I am working on a module for Orchard.
What I can't understand is that you are almost mandatored to use Content Parts or Content Types in Orchard, while I just want to get my data from the database en show it my way, not in some article.
Why is this? Is there some way to build a module the way you should do it in ASP.NET MVC, without using all the Orchard stuff? I have been looking at several tutorials, but they are all using parts and drivers and so on.
EDIT:
Machine.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace PowerAll.Voorraad.Models
{
public class MachineRecord
{
public int Id { get; set; }
public int MachineNumber { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public char PriceType { get; set; }
public decimal Price { get; set; }
public int Year { get; set; }
}
}
Migrations.cs
namespace PowerAll.Voorraad
{
public class Migrations : DataMigrationImpl
{
public int Create()
{
SchemaBuilder.CreateTable("MachineRecord", table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<int>("MachineNumber", column => column.NotNull())
.Column<string>("Title", column => column.NotNull().WithLength(40))
.Column<string>("Description", column => column.WithLength(70))
.Column<char>("PriceType", column => column.NotNull().WithLength(1))
.Column<decimal>("Price", column => column.NotNull())
.Column<int>("Year", column => column.WithLength(4))
);
// Return the version that this feature will be after this method completes
return 1;
}
}
}
MachineController.cs
namespace PowerAll.Voorraad.Controllers
{
[Themed]
public class MachineController : Controller
{
private readonly IRepository<MachineRecord> machineRecords;
public MachineController(IRepository<MachineRecord> MachineRecords) {
machineRecords = MachineRecords;
}
public ActionResult Index() {
// Here we're just grabbing records based on some fictional "Deleted" flag
var items = machineRecords.Table;
// Items is now an IEnumerable<MachineRecord>
return View(items);
}
}
}
Index.cshtml
@model IEnumerable<PowerAll.Voorraad.Models.MachineRecord>
<ul>
@foreach(var item in Model) {
<li>@item.Id</li>
<li>@item.MachineNumber</li>
<li>@item.Title</li>
<li>@item.Description</li>
<li>@item.PriceType</li>
<li>@item.Price</li>
<li>@item.Year</li>
}
</ul>
Hello from view
'Hello from view' is visible, so I really get to my view.