Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3361918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:12:38+00:00 2026-05-18T03:12:38+00:00

I’m working on a UserViewModel, and I’m wondering if it’s appropriate to do minor

  • 0

I’m working on a UserViewModel, and I’m wondering if it’s appropriate to do minor calculations in the VM, or if I need to separate it further and calculate elsewhere.

Public Class UserViewModel
    Public Property UserName As String
    Public Property Email As String
    Public Property Website As String
    Public Property ID As Integer
    Public Property OpenIds As List(Of OpenID)
    Public Property UserAge As String
    Public Property About As String
    Public Property Slug As String
    Public Property LastSeen As String
    Public Property Region As String
    Public Property MemberSince As String
    Public Property Reputation As String
    Public Property isUserMatch As Boolean = False
    Private MarkDownSharp As MarkdownSharp.Markdown

    Public Sub New(ByVal user As User)
        Dim currentuser As Authentication.AuthUserData = Authentication.CustomAuthentication.RetrieveAuthUser
        MarkDownSharp = New MarkdownSharp.Markdown
        With MarkDownSharp
            .AutoHyperlink = False
            .AutoNewLines = True
            .EncodeProblemUrlCharacters = True
            .LinkEmails = True
            .StrictBoldItalic = True
        End With

        _UserName = If(Not user.UserName Is Nothing, user.UserName, "User" & user.ID.ToString)
        _Email = user.Email
        _Website = user.WebSite
        _ID = user.ID
        _OpenIds = user.OpenIDs.ToList
        ''# Converts the users birthdate to an age representation
        ''#      IE: 29
        _UserAge = user.BirthDate.ToAge

        ''# Because some people can be real ass holes and try to submit bad
        ''# data (scripts and shitè) we have to modify the "About" content in
        ''# order to sanitize it.  At the same time, we transform the Markdown
        ''# into valid HTML. The raw input is stored without sanitization in
        ''# the database.  this could mean Javascript injection, etc, so the
        ''# output ALWAYS needs to be sanitized.
        _About = Trim(Utilities.HtmlSanitizer.Sanitize(MarkDownSharp.Transform(user.About)))

        ''# Removes spaces from Usernames in order to properly display the
        ''# username in the address bar
        _Slug = Replace(user.UserName, " ", "-")

        ''# Returns a boolean result if the current logged in user matches the
        ''# details view of the user in question.  This is done so that we can
        ''# show the edit button to logged in users.
        _isUserMatch = If(currentuser.ID = user.ID, True, False)


        ''# Grabs the users registration data and formats it to a time span
        ''# The "timeago-nosuffix" CssClass is there to remove the "ago"
        ''# suffix from the "member for" string. Cuz when you think about
        ''# it... "Member for 5 days ago" just sounds stupid.
        _MemberSince = user.MemberSince.ToTimeSpan("timeago-nosuffix")

        ''# Grabs the users last activity and formats it to a time span
        _LastSeen = user.ActivityLogs.Reverse.FirstOrDefault.ActivityDate.ToTimeSpan("timeago", "ago")

        ''# Formats the users reputation to a comma Deliminated number 
        ''#    IE: 19,000 or 123k
        _Reputation = user.Reputation.ToShortHandNumber


        ''# Get the name of the users current Region.
        _Region = user.Region.Region.FirstOrDefault
    End Sub

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:12:38+00:00Added an answer on May 18, 2026 at 3:12 am

    If those calculations concern formatting for the given view then it is the exact place. It seems you are doing exactly this: formatting for the view which is OK (sorry if I’ve missed something, my VB.NET code reading skills start to elude me :-)). If on the other hand it is some domain logic it is probably better suited to the model so that it can be reused.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I need to clean up various Word 'smart' characters in user input, including but
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.