Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Create(FormCollection input)
- {
- var product = contentManager.New<ProductPart>("Product");
- product.Description = input["Description"];
- product.Sku = input["Sku"];
- product.Price =Convert.ToDecimal(input["Price"]);
- if (!ModelState.IsValid)
- {
- return View(product);
- }
- contentManager.Create(product);
- return RedirectToAction("Index");
- }
- public static T New<T>(this IContentManager manager, string contentType)
- where T : class, IContent {
- var contentItem = manager.New(contentType);
- if (contentItem == null)
- return null;
- var part = contentItem.Get<T>();
- if (part == null)
- throw new InvalidCastException();
- return part;
- }
- public class ProductRecord:ContentPartRecord
- {
- // public virtual int Id { get; set; }
- public virtual string Sku { get; set; }
- public virtual string Description { get; set; }
- public virtual decimal Price { get; set; }
- }
- public class ProductPart : ContentPart<ProductRecord>
- {
- /*
- public int Id
- {
- get { return Record.Id; }
- set{Record.Id = value;}
- }
- */
- [Required]
- public string Sku
- {
- get { return Record.Sku; }
- set { Record.Sku = value; }
- }
- [Required]
- public string Description
- {
- get { return Record.Description; }
- set{ Record.Description = value;}
- }
- [Required]
- public decimal Price
- {
- get { return Record.Price; }
- set { Record.Price = value; }
- }
- }
- public class Migrations : DataMigrationImpl
- {
- public int Create()
- {
- SchemaBuilder.CreateTable("ProductRecord",
- table =>
- {
- table.ContentPartRecord()
- .Column<string>("Sku")
- .Column<string>("Description")
- .column<decimal>("Price");
- });
- ContentDefinitionManager.AlterTypeDefinition("Product", cfg => cfg.WithPart("ProductPart"));
- return 1;
- }
- }
- public int Create() {
- SchemaBuilder.CreateTable("ProductRecord",
- table => table
- .ContentPartRecord()
- .COLUMNS NEED TO BE SPECIFIED
- );
- ContentDefinitionManager.AlterTypeDefinition("Forum",
- cfg => cfg
- .WithPart("ProductPart")
- .WithPart("CommonPart")
- );
Add Comment
Please, Sign In to add comment