Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Greg McMullen 49 posts 195 karma points
    Mar 07, 2013 @ 20:16
    Greg McMullen
    0

    Sorting Members with Query Parameters (or other method)

    I'm hoping to create a staff/faculty list with the ability to choose between an individual Employee Type and Department.

    I'm thinking a way to do it would be through Query Parameters (I do not have experience with user controls, nor do I have access to put them into effect).

    Member Types: Faculty / Staff
    Member Groups: Math / ChemE / Mechanical / etc.

    @using umbraco.cms.businesslogic.member
    @{
        var memberId= HttpContext.Current.Request.QueryString["id"];
        if(memberId != null) {
            @* Individual Profile - Show Member based off of QueryString ID *@
            var member = new Member(Convert.ToInt32(memberId));
            var userName = member.Text;
            var headshot = "";
            var title = "";
            var phoneNumber = "";
            var officeLocation = "";
            var bio = "";
    
            if ( member.HasProperty("phone") && member.getProperty("phone").Value.ToString() != "" ){
                phoneNumber = member.getProperty("phone").Value.ToString();
            }
            if ( member.HasProperty("titles") && member.getProperty("titles").Value.ToString() != "" ){
                title = member.getProperty("titles").Value.ToString();
            }
            if ( member.HasProperty("officeLocation") && member.getProperty("officeLocation").Value.ToString() != "" ){
                officeLocation = member.getProperty("officeLocation").Value.ToString();
            }
            if ( member.HasProperty("name") && member.getProperty("name").Value.ToString() != "" ){
                userName = member.getProperty("name").Value.ToString();
            }
            if ( member.HasProperty("biography") && member.getProperty("biography").Value.ToString() != "" ){
                bio = member.getProperty("biography").Value.ToString();
            }
            @* Display properties *@
            <h2>@userName</h2>
            <div style="float:right; margin:0 25px 10px 0; background:#e9e9e9; text-align:center; padding:10px;">
            @if ( member.HasProperty("headshot") && member.getProperty("headshot").Value.ToString() != "" ){
                headshot = member.getProperty("headshot").Value.ToString();
                <img src="@headshot" alt="Photo of @userName" style="text-align:center; margin:0 auto;" title="Photo of @userName" />
            }
            <p style="text-align:left; font-size:1.2em"><strong>Office:</strong> @officeLocation
                <br /><strong>Phone:</strong> @phoneNumber</p>
            </div>
            @Html.Raw(@bio)
        } else {
        <table style="border-collapse:collapse; font-size:1.3em;">
            <thead style="background:ccc; font-weight:bold; border:solid 1px #ccc;">
                <td style="padding:7px 20px;">Name</td>
                <td style="padding:7px 20px;">Title / Department</td>
                <td style="padding:7px 20px;">Office Location</td>
                <td style="padding:7px 20px;"> </td>
            </thead>
            <tbody style="background:#e9e9e9; border:#ccc 1px solid; padding:7px 20px;">
    
        @foreach(var item in Member.GetAll){
            <tr style="border-bottom:dashed 1px #ccc;">
                <td style="padding:7px 20px;">
                @if ( @item.HasProperty("name") && @item.getProperty("name").Value.ToString() != "" ) {
                    if ( @item.HasProperty("biography") && @item.getProperty("biography").Value.ToString() != "" ){
                        <a href="[email protected]" title="Full Bio for @item.Text">@item.getProperty("name").Value.ToString()</a>
                    } else{
                        @item.getProperty("name").Value.ToString()
                    }
                } else { @item.Text }
    
                @if ( @item.HasProperty("phone") && @item.getProperty("phone").Value.ToString() != "" ){
                    var phone = @item.getProperty("phone").Value.ToString();
                    <br /><a href="tel:@phone">@phone</a>
                }
                </td>
                <td style="padding:7px 20px;">@if ( @item.HasProperty("titles") && @item.getProperty("titles").Value.ToString() != "" ){
                    @item.getProperty("titles").Value.ToString()
                }</td>
                <td style="padding:7px 20px;">@if ( @item.HasProperty("officeLocation") && @item.getProperty("officeLocation").Value.ToString() != "") {
                    @item.getProperty("officeLocation").Value.ToString()
                }</td>
                <td style="padding:7px 20px;">@if ( @item.HasProperty("headshot") && @item.getProperty("headshot").Value.ToString() != "" ) {
                    var headshot = @item.getProperty("headshot").Value.ToString();
                    <img src="/imagegen.ashx?width=60&image=@headshot" alt="@item.Text" title="@item.Text" />
                }
                </td>
            </tr>
        }
            </tbody>
        </table>
    }
    }
  • Charles Afford 1163 posts 1709 karma points
    Mar 10, 2013 @ 11:39
    Charles Afford
    1

    I think what you should do here is create a member model which has some properties and a method of two.  Assuming your are in a partial view, create a new instance of the member member model in your view and pass it into this partial.  Then in your partial at the very top use @model namespace.modelname.  You can then use @Model.propertyinmodel.  This will aloow you to have alot more control about what is happening with your data, you should not have logic in your views :).  Let me know if this helps :)  Charlie :)

  • Greg McMullen 49 posts 195 karma points
    Mar 11, 2013 @ 15:11
    Greg McMullen
    0

    Charlie,

    I appreciate your response, but I have absolutely NO idea how to implement what you are talking about. Any examples or suggestions of how to do this?

  • Charles Afford 1163 posts 1709 karma points
    Mar 13, 2013 @ 14:27
    Charles Afford
    1

    Hi sorry for my late reply :).

    Coudl you tell me if you are in a partial view or a view in the code you have above?  Also what version of Umbraco are you using?  As the umbraco member is now not used, You use the membership provider instead.  Have a look a the documentation @ http://our.umbraco.org/wiki/how-tos/membership-providers.

    Let me know  and i will be able to help out some more :).

    Are you using MVC?  Charlie :)

  • Greg McMullen 49 posts 195 karma points
    Mar 13, 2013 @ 14:32
    Greg McMullen
    0

    No worries Charlie, I just appreciate any help.

    I honestly have no idea if I'm using MVC or WebForms. Some of our templates use the <form> wrapper, others don't.

    Live site is 4.11.1 (which is where this code will [hopefully] end up some day). The testing enviro I am using is a local install with WebMatrix is 4.11.3.

    The code above is just a MacroScript (not sure where that falls), could you please explain the "partial view" vs "view"?

  • Andreas Iseli 150 posts 427 karma points
    Mar 13, 2013 @ 14:42
    Andreas Iseli
    1

    Hey Greg, are you familiar with the MVC Pattern as it? Here is a simple explanation:

    http://jordanhall.co.uk/programming/simple-explanation-of-model-view-controller-mvc-2206990/

    Generally you divide your logic code (controller) from the HTML rendering (view) and provide only the data to display from the controller to the view using a model object. In the view you are going to use Razor (which comes with .NET 4) as successor of the inline-code to select the data to display from the model. It easy really easy to place it where you have to.

    This umbraco blog will also help you to sort it out and tells you more about views in Umbraco:

    http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

    Regards

  • Greg McMullen 49 posts 195 karma points
    Mar 13, 2013 @ 14:51
    Greg McMullen
    0

    Okay, after reading through those resources, I'd say we are using partial views, for most (if not all) of our Macros.

    Everything in our site was setup prior to the current team arriving, at it was setup in 2009 using XSLT.

    Okay, with that out of the way. Now what do I do? *confused look*

    Thanks Andreas!

  • Andreas Iseli 150 posts 427 karma points
    Mar 13, 2013 @ 14:57
    Andreas Iseli
    1

    Razor makes your coding-life easier :) Are you abel to deploy custom code (DLLs respectively) or do you just want to create macros through the backoffice?

  • Greg McMullen 49 posts 195 karma points
    Mar 13, 2013 @ 15:00
    Greg McMullen
    0

    This is where we run into the problems. Our department (marketing) doesn't have access to the backend of the server, so uploading a DLL or .ascx file is complicated and/or impossible to do. 

    Through the backoffice interface we can create the .cshtml files for razor scripts (which we've done for other projects).

    In my local test enviro, obviously, I can do whatever I want. But I try to recreate what I actually have access to.

  • Charles Afford 1163 posts 1709 karma points
    Mar 13, 2013 @ 15:27
    Charles Afford
    1

    If you continue you to do it this way you are going to run in to trouble imo.  You need to deploy some custom code in a dll.  Granted this we take resource and time but it will save you pain in the future.   :).  Charlie.  The code you have there are the moment, could be chopped down alot, and using the inline styles for the css should be in a style sheet :).

  • Andreas Iseli 150 posts 427 karma points
    Mar 13, 2013 @ 15:31
    Andreas Iseli
    1

    Okay this makes it a bit more complicated but you should still be able to split up your code. I have the following suggestion for you:

    A partial macro view: Here you use razor to build your member model object (use a hashlist or so) and then you pass it to another view.

    Another view: This is a simple partial view taking your model object and contains all other logic for displaying whatever you want.

     

    I've not tested something yet because I always deploy my own DLLs, but you may give it a try. Anyway Charles is right about the complexity and risks. You may run into a neverending story.

  • Greg McMullen 49 posts 195 karma points
    Mar 13, 2013 @ 15:35
    Greg McMullen
    0

    Charlie: Oh absolutely, I do agree to the stylesheet. I typically code with inlines (to avoid multiple screens/windows) initially to get what I want, then take them out and put them in the approrpriate CSS file. I'm really not sure what I'm hoping to get out of this particular set of code, but I do know that I want a full list of members and individual member profiles. At the moment, this seemed like a viable option.

    Honestly, I'm not sure why I'm doing this anyway, history dictates that my ventures are for naught and moreso my own education. Instead of actually being allowed to code working features for the site.

    Thanks for the input and I'll keep digging.

    Any useful sites/tutorials on how to use the DLL route?

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2013 @ 18:48
    Charles Afford
    0

    Hi greg sorry for the late reply.  did not get notified.  Unless you no about makeing dll's and the asp.net membership provdier ect ect, it could be complicated to impliment in a working system.  Althought i dont know your exp in .net c#.  Anyway if you need a hand give us a shout and i will do my best :) Charles :).

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2013 @ 18:50
  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2013 @ 18:51
Please Sign in or register to post replies

Write your reply to:

Draft