Guest User

Untitled

a guest
Jul 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. public ActionResult Create(FormCollection input)
  2. {
  3. var product = contentManager.New<ProductPart>("Product");
  4. product.Description = input["Description"];
  5. product.Sku = input["Sku"];
  6. product.Price =Convert.ToDecimal(input["Price"]);
  7.  
  8. if (!ModelState.IsValid)
  9. {
  10. return View(product);
  11. }
  12.  
  13. contentManager.Create(product);
  14.  
  15. return RedirectToAction("Index");
  16. }
  17.  
  18. public static T New<T>(this IContentManager manager, string contentType)
  19. where T : class, IContent {
  20. var contentItem = manager.New(contentType);
  21. if (contentItem == null)
  22. return null;
  23.  
  24. var part = contentItem.Get<T>();
  25. if (part == null)
  26. throw new InvalidCastException();
  27.  
  28. return part;
  29. }
  30.  
  31. public class ProductRecord:ContentPartRecord
  32. {
  33. // public virtual int Id { get; set; }
  34.  
  35.  
  36. public virtual string Sku { get; set; }
  37.  
  38.  
  39. public virtual string Description { get; set; }
  40.  
  41.  
  42. public virtual decimal Price { get; set; }
  43.  
  44.  
  45. }
  46.  
  47.  
  48.  
  49. public class ProductPart : ContentPart<ProductRecord>
  50. {
  51. /*
  52. public int Id
  53. {
  54. get { return Record.Id; }
  55. set{Record.Id = value;}
  56. }
  57. */
  58.  
  59. [Required]
  60. public string Sku
  61. {
  62. get { return Record.Sku; }
  63. set { Record.Sku = value; }
  64. }
  65.  
  66. [Required]
  67. public string Description
  68. {
  69. get { return Record.Description; }
  70. set{ Record.Description = value;}
  71. }
  72.  
  73. [Required]
  74. public decimal Price
  75. {
  76. get { return Record.Price; }
  77. set { Record.Price = value; }
  78. }
  79.  
  80.  
  81. }
  82.  
  83. public class Migrations : DataMigrationImpl
  84. {
  85.  
  86. public int Create()
  87. {
  88. SchemaBuilder.CreateTable("ProductRecord",
  89. table =>
  90. {
  91. table.ContentPartRecord()
  92. .Column<string>("Sku")
  93. .Column<string>("Description")
  94. .column<decimal>("Price");
  95. });
  96.  
  97. ContentDefinitionManager.AlterTypeDefinition("Product", cfg => cfg.WithPart("ProductPart"));
  98.  
  99. return 1;
  100. }
  101. }
  102.  
  103. public int Create() {
  104. SchemaBuilder.CreateTable("ProductRecord",
  105. table => table
  106. .ContentPartRecord()
  107. .COLUMNS NEED TO BE SPECIFIED
  108. );
  109.  
  110. ContentDefinitionManager.AlterTypeDefinition("Forum",
  111. cfg => cfg
  112. .WithPart("ProductPart")
  113. .WithPart("CommonPart")
  114. );
Add Comment
Please, Sign In to add comment