Developer forum

Forum » Development » Problem with hardcoded area id

Problem with hardcoded area id

Anders Ebdrup
Anders Ebdrup
Reply

Hi Dynamicweb,

We have an issue with a solution with no area with ID = 1, which gives exceptions various places in the administration.

The issue is related to this code section. Can "areaService.GetArea(1)" be changed to finding "FirstOrDefault()"?

        Private Shared Function GetCurrentArea() As Area
            Dim areaService As IAreaService = Services.Areas
            Dim result As Area = Nothing

            If Not IsNothing(Context.Current) AndAlso Not IsNothing(Context.Current.Session) AndAlso Not IsNothing(Context.Current.Session("DW_Area")) Then
                Dim areaId As Integer = Converter.ToInt32(Context.Current.Session("DW_Area"))

                If (areaId > 0) Then
                    result = areaService.GetArea(Converter.ToInt32(Context.Current.Session("DW_Area")))
                End If
            End If

            If result Is Nothing Then
                result = areaService.GetArea(1)
            End If

            Return result
        End Function

 

Best regards,

Anders


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

TFS#62185, merged to 9.6, released with next hotfix.

Made it like this to keep compatibility:

If result Is Nothing Then
                result = areaService.GetArea(1)
            End If
            If result Is Nothing Then
                If areaService.GetAreas.Any() Then
                    Return areaService.GetAreas().FirstOrDefault
                End If
            End If

Also changed one other place in ecommerce that did something similar.

BR Nicolai

Votes for this answer: 1
 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Anders

The feature #62185 regarding "Area 1" has been implemented in Dynamicweb Hotfix version 9.6.10

To upgrade please choose this version from download:

http://doc.dynamicweb.com/releases-and-downloads/releases

Let me know if you need any more help regarding this

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 

You must be logged in to post in the forum