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

  • Home
  • SEARCH
  • 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 149015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:03:40+00:00 2026-05-11T09:03:40+00:00

As I’ve stated before I’m working on a digg clone to teach myself ASP.NET

  • 0

As I’ve stated before I’m working on a digg clone to teach myself ASP.NET MVC Inside and out but I’ve hit a road bump that I can’t seem to avoid.

I want to be able to optimize this application as much as possible so I have my DAL which is a bunch of classes of …Repository : Repository. Now to help optimize for performance I have my base repository classes return my ViewData objects so that they can select extra fields needed without having to create an anonymous type.

Stories have Users who have created them and Users have Votes for Stories. Pretty easy DB layout. Now I handle my own membership because the default ASP.NET membership is so bloated. In my view for the list of stories I have to determine if the current user has voted on the story being rendered. Now since I figured data access in the View shouldn’t be happening it should be in either my controller or my DAL. Since I’m already returning ViewData from my DAL i added another property on the StoryViewData type named ‘UserVotedOn’ that returns true if the user has voted on that story.

Problem with this is I have to either A) make the DAL aware of membership or B) pass in the User ID into the query methods on the DAL. Neither of these feel right to me and I’m looking for some good solutions. Any feedback is welcome.

  • 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. 2026-05-11T09:03:41+00:00Added an answer on May 11, 2026 at 9:03 am

    In my MVC apps I’m using architecture that Rob Conery showed on his MVC Storefront video series and it works like charm for me.

    Repository => Service + Filters => Controller => View

    I’ve tried to simulate what you want to achieve and managed todo like this

    Edit1: Changed IList to IQueryable in repository and filters

    Repository

    public interface IRepository {     IQueryable<Vote> GetVotes();     IQueryable<Story> GetStories(); } 

    Service for getting what you want

    public class Service : IService {     private IRepository _repository;      public Service(IRepository repository)     {         _repository = repository;         if (_repository == null) throw new InvalidOperationException('Repository cannot be null');     }     public IList<Vote> GetUserVotes(int userID)     {         return _repository.GetVotes().WithUserID(userID).ToList();     }     public IList<Story> GetNotVotedStories(IList<Vote> votes)     {         return _repository.GetStories().WithoutVotes(votes).ToList();     } } 

    Filters to filter your stories and user votes (These are basically extension methods). Not the nicest implementation out there, but you can rewrite later

    public static class Filters {     public static IQueryable<Vote> WithUserID(this IQueryable <Vote> qry, int userID)     {         return from c in qry                where c.UserID == userID                select c;     }     public static IQueryable<Story> WithoutVotes(this IQueryable <Story> qry, IList <Vote> votes)     {         return  from c in qry                 where votes.Where(x => x.StoryID == c.StoryID).ToList().Count > 0                 select c;     } } 

    And then you can pass current UserID in controller, not in DAL or View like you had to do before

    public class HomeController : Controller {     private readonly IRepository _repository;     private readonly IService _service;      public HomeController()     {         _repository = new Repository();         _service = new Service.Service(_repository);     }      public ActionResult Index()     {         var userVotes = _service.GetUserVotes(CurrentUserID);         var unvotedStories = _service.GetNotVotedStories(userVotes);          return View(unvotedStories);     } } 

    This allows you to stay away from adding user related UserVotedOn property to your Story model

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

Sidebar

Ask A Question

Stats

  • Questions 134k
  • Answers 134k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer try to see this code, might need some debugging though… May 12, 2026 at 6:47 am
  • Editorial Team
    Editorial Team added an answer I suggest you read up on AJAX. Here's a PHP… May 12, 2026 at 6:47 am
  • Editorial Team
    Editorial Team added an answer &apos; is an XML feature. It isn't allowed in HTML… May 12, 2026 at 6:47 am

Related Questions

I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
As I learn more and more about OOP, and start to implement various design

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.