[Dev] Modification Module Maps by adding Zoom in database

Topics: Customizing Orchard
May 21, 2013 at 3:48 PM
Edited May 21, 2013 at 3:54 PM
Hi,

I modify the module Maps from http://docs.orchardproject.net/Documentation/Writing-a-content-part by adding the zoom in the model and update the migration by using
public void InitCreate()
        {
            // Creating table PoiRecord
            SchemaBuilder.CreateTable("MapRecord", table => table
                  .ContentPartRecord()
                  .Column("Latitude", DbType.Double)
                  .Column("Longitude", DbType.Double)
                  .Column("Zoom",DbType.Int32)
              );

            ContentDefinitionManager.AlterPartDefinition(
                typeof(MapPart).Name, cfg => cfg.Attachable());
        }

        public int UpdateFrom1()
        {
            SchemaBuilder.DropTable("MapRecord");
            InitCreate();
            return 2;
        }
I obtain the issue below after to reactivate the module.
Server Error in '/OrchardLocal' Application.

The model item passed into the dictionary is of type 'IShapeProxye76e639d4d7d469d87bbd077cec43cf6', but this dictionary requires a model item of type 'Maps.Models.MapPart'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'IShapeProxye76e639d4d7d469d87bbd077cec43cf6', but this dictionary requires a model item of type 'Maps.Models.MapPart'.

Source Error: 


Line 132:
Line 133:            var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
Line 134:            var result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
Line 135:
Line 136:            Logger.Information("Done rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
I modify the map.cs by
public class MapRecord : ContentPartRecord
    {
        public virtual double Latitude { get; set; }
        public virtual double Longitude { get; set; }
        public virtual int Zoom { get; set; }
    }

    public class MapPart : ContentPart<MapRecord>
    {
        [Required]
        public double Latitude
        {
            get { return Record.Latitude; }
            set { Record.Latitude = value; }
        }

        [Required]
        public double Longitude
        {
            get { return Record.Longitude; }
            set { Record.Longitude = value; }
        }

        public int Zoom
        {
            get { return Record.Zoom;  }
            set { Record.Zoom = value; }
        }
    }
I think it's because ((IShapeProxyd595b3b09c224a19ba6f51369fa8a0dd)(displayContext.Value)).__target doesn't have the Zoom available, I notice nevertheless the Longitude and Latitude element. so ... :(
Any idea?
May 21, 2013 at 4:58 PM
I try to rollback by modifify Migrations.

and launch the script
update [dbo].[Orchard_Framework_DataMigrationRecord]
set Version=1
where DataMigrationClass='Maps.Migrations'

I add a breakpoint and each time doesn't go in the UpdateFrom2(), very weird, I search.
public class Migrations : DataMigrationImpl {

        public int Create()
        {
            // Creating table MapRecord
            SchemaBuilder.CreateTable("MapRecord", table => table
                .ContentPartRecord()
                .Column("Latitude", DbType.Double)
                .Column("Longitude", DbType.Double)
            );

            ContentDefinitionManager.AlterPartDefinition(
                typeof(MapPart).Name, cfg => cfg.Attachable());
            return 1;
        }

        public void InitCreate()
        {
            // Creating table PoiRecord
            SchemaBuilder.CreateTable("MapRecord", table => table
                  .ContentPartRecord()
                  .Column("Latitude", DbType.Double)
                  .Column("Longitude", DbType.Double)
                  //.Column("Zoom",DbType.Int32)
              );

            ContentDefinitionManager.AlterPartDefinition(
                typeof(MapPart).Name, cfg => cfg.Attachable());
        }

        public int UpdateFrom1()
        {
            SchemaBuilder.DropTable("MapRecord");
            InitCreate();
            return 2;
        }

        public int UpdateFrom2()
        {
            SchemaBuilder.DropTable("MapRecord");
            InitCreate();
            return 3;
        }
May 22, 2013 at 9:44 AM
Edited May 22, 2013 at 9:49 AM
Hi,

The image is on https://docs.google.com/file/d/0B9NwsLBZK3LnR1dGWFNwN1NSVWM/edit?usp=sharing

I obtain the error message "The model item passed into the dictionary is of type 'IShapeProxyd6957fc85e6541bda7d6a2e1d2c041d1', but this dictionary requires a model item of type 'CustMap.Models.CustMapPart'."

But I notice in the , displayContext.Value from the line breaked result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
I habe the object CustMap.Models.CustMaPart.
-       displayContext.Value    {IShapeProxyd6957fc85e6541bda7d6a2e1d2c041d1}   object {IShapeProxyd6957fc85e6541bda7d6a2e1d2c041d1}
+       __interceptors  {Castle.Core.Interceptor.IInterceptor[1]}   Castle.Core.Interceptor.IInterceptor[]
-       __target    {ShapeProxyeeb13b9f57b345a589b57276ba71ed26}    object {ShapeProxyeeb13b9f57b345a589b57276ba71ed26}
+       Attributes  Count = 0   System.Collections.Generic.IDictionary<string,string> {System.Collections.Generic.Dictionary<string,string>}
+       Classes Count = 0   System.Collections.Generic.IList<string> {System.Collections.Generic.List<string>}
        Longitude    0.0    Orchard.DisplayManagement.Shapes.ShapeDebugView.KeyValuePairs
        Latitude     0.0    Orchard.DisplayManagement.Shapes.ShapeDebugView.KeyValuePairs
        Zoom     0  Orchard.DisplayManagement.Shapes.ShapeDebugView.KeyValuePairs
+       ContentItem  {Orchard.ContentManagement.ContentItem}    Orchard.DisplayManagement.Shapes.ShapeDebugView.KeyValuePairs
-       ContentPart  {CustMap.Models.CustMapPart}   Orchard.DisplayManagement.Shapes.ShapeDebugView.KeyValuePairs
+       base    {CustMap.Models.CustMapPart}    Orchard.ContentManagement.ContentPart<CustMap.Models.CustMapRecord> {CustMap.Models.CustMapPart}
        Latitude    0.0 double
        Longitude   0.0 double
        Zoom    0   int
+       Dynamic View    Expanding the Dynamic View will get the dynamic members for the object  
        Id  null    string
+       Items   Count = 0   System.Collections.Generic.IEnumerable<dynamic> {System.Collections.Generic.List<object>}
+       Metadata    {Orchard.DisplayManagement.Shapes.ShapeMetadata}    Orchard.DisplayManagement.Shapes.ShapeMetadata
+       Raw View        
+       Metadata    {Orchard.DisplayManagement.Shapes.ShapeMetadata}    Orchard.DisplayManagement.Shapes.ShapeMetadata
+       Static members      
+       Dynamic View    Expanding the Dynamic View will get the dynamic members for the object  
Difficult to customize Orchard :(
May 22, 2013 at 2:31 PM
Hi,

I found the solution.
I need to remove from the file ~/Views/Parts/CustMap.cshtml the first line.

@model CustMap.Models.CustMapPart
<p>Map element</p> @*

@Model.Latitude - @Model.Longitude - @Model.Zoom

*@
<img alt="Location" border="1" src="http://maps.google.com/maps/api/staticmap?zoom=14&size=256x256&maptype=roadmap&markers=color:blue|@Model.Latitude,@Model.Longitude&sensor=false" /> Enjoy!