9
votes
1answer
2k views

Is this the right way to inject AutoMapper profiles

I'd like to know if I'm doing profile configuration in the wrong place or in the wrong way. I'm following the Onion Architecture. So that restricts the direction of my dependencies towards the ...
4
votes
2answers
1k views

Using a recurring System.Threading.Timer in an Mvc Application

I'd like your opinion on something. I have the following class: ...
3
votes
0answers
82 views

PreWarmCache for MVC Application with Stopwatch Infinite Loop

I used the information from the article "Auto-Start ASP.NET Applications (VS 2010 and .NET 4.0 Series)" to create a background task that runs on an infinite loop. Ultimately, this program is going to ...
4
votes
4answers
624 views

Instantiating if null

I often have static classes which uses the DataContext somehow, and they all make a new DataContext, but often I already have ...
6
votes
1answer
3k views

ListBox for a many-to-many relationship

I'm looking for a good and easy to use solution for creating MultiSelectLists in MVC for many-to-many relationships. I have this following example code and it works fine, but it just takes a lot of ...
3
votes
1answer
3k views

Following Repository Pattern properly

I am new to learning Repository Pattern. I am developing a site in MVC 4 (I'm new to it as well). The way I am using Repository pattern as follows: I created ...
3
votes
2answers
330 views

Cookie wrapper in MVC4

I'd like to create a cookie wrapper in my application to help support a DRY approach to coding common cookie methods, provide IntelliSense for cookie-type properties (keys), and protect against ...
5
votes
1answer
84 views

Where to put hidden fields when displaying entities properties in a table?

Let's say that I have a view, whose purpose is to show a table with some information about a person entity. The view contains a form with an input element that the user can use to add a new person to ...
3
votes
3answers
216 views

Entity Framework with multiple connections open?

I'm learning Entity Framework and I'm wondering if this code is the proper way of doing this. Basically this is my attempt at refactoring a very long controller in ASP.Net MVC 4. I'm using Entity ...
5
votes
3answers
154 views

Calculating total sales from each member

I am building a new system that is using some tables from an old system. For each user on this new system, I need to go to the old system and total up their sales. Currently it takes between 2-5 ...
1
vote
1answer
90 views

Class to Return Single Integer

I have a class used to return a single integer, but think there is room for improvement. The class should only return a single row every time and if no row is found it might be a good idea to throw an ...
2
votes
2answers
1k views

Truncate port number from absolute Uri

We had a requirement to remove the port number from the Request.Url.AbsoluteUr i.e Actual: ...
8
votes
2answers
186 views

Accessing server side variables in views and JavaScript

Here is the snippet of my code: /Views/Emp/EditEmp.aspx ...
3
votes
1answer
235 views

Populate Drop Down List from SQL Database

I am populating a drop down list from my SQL database. List should be able to be displayed with active only, inactive only or both at the same time. OfficeRepository.cs: ...
4
votes
1answer
169 views

How can I simplify these if/else clauses?

I have a few if, else-if, else clauses. The only ...
2
votes
2answers
109 views

Returns Office Details from Database

I am building an Administration web site for the Office details in my database. Right now, I am just trying to display the office details. ...
7
votes
3answers
423 views

Ternary extension method

I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup. Is there a better way to write this ...
0
votes
1answer
30 views
5
votes
2answers
9k views

Update only modified fields in Entity Framework

I'm working on a website on ASP.NET MVC4 and EF5. I want to ensure that only modified values are updated in the database. I'm using a unit of work pattern and repositories for data work. Here's the ...
1
vote
0answers
1k views

Code First/Database First Entity Framework MVC [closed]

The following example is taken from the book Pro ASP.NET MVC 4 - Adam Freeman. This book does a good job going over the basics of the MVC framework. In it a ...
1
vote
1answer
115 views

Inserting using multiple contexts into LocalDB

I've written this ActionResult to model an Order that goes through. I couldn't think of another way to write this without using context ...
5
votes
2answers
1k views

Building a better Data Access Layer Class

Since I am new to MVC and the Entity Framework, I have been struggling to grasp the concept of creating useful Data and Service layers. I have come across a scenario where I believe my code has become ...
3
votes
1answer
88 views

Retrieving statistics about URL clicks

I'm pretty new to ASP/MVC but have had some prior programming experience. I am trying to retrieve statistics about URL clicks - total clicks and unique clicks by IP address. I started with: ...
8
votes
1answer
545 views

Injecting SelectList objects into ViewData to enable using EditorFor on dropdown based properties?

I have developed a system whereby I use an attribute to state which SelectList to use for an 'FK' property. I would appreciate some feedback mainly on by good ...
3
votes
1answer
4k views

Unit of Work with Repository Pattern MVC 5 & EF 6

I put together a sample of how I am using the Unit of Work & Repository pattern based on my understanding. Can anyone please let me know if I am implementing this the correct way? If I am not, how ...
6
votes
2answers
474 views

Reduce spaghetti code in ASP.NET MVC

I just started working with asp.net mvc a few weeks ago, and I'm finding that it can be very easy to write spaghetti code in the controllers. For my first project, I created a very simple view with a ...
4
votes
1answer
140 views

MVC4 Routes, using Default

Should I leave the Default Route in if it's not adding any benefit? I have a RouteConfig.cs file that looks like this: ...
3
votes
1answer
1k views

Unit of work, Ninject, Repository and WebAPI implementation

after recently getting a bulk of work done on my WebAPI service layer, I thought I'd post some of my working on here for you guys to tear apart, generally, most of it 'feels' mostly okay, but I know ...
3
votes
1answer
380 views

Multiple Ajax Requests per MVC 4 View

I'm using the repository pattern with a context and ninject as the IOC. I have a service which handles getting and setting page properties in the database. ...
5
votes
2answers
2k views

MVC Layered Project Structure

We are starting a new web project using C# / MVC 4 and Entity Framework 5 for data access. I've decided to go with an n-layered approach for the structure of the project and I would like some feedback ...
2
votes
1answer
475 views

Improving MVC 4 DropDownList

I'm currently populating my drop downlists like this... ...
2
votes
1answer
115 views
1
vote
1answer
186 views

Creating models manually in mvc

I am creating my models manually. I have five tables in my database as follows : 1. Members 2. MemberTypeMasters 3. Payments 4. Relationships 5. StatusMasters ...
2
votes
1answer
2k views

When to use separate DBContext classes?

I know that the DBContext represents a session (Unit-Of-Work and Repository) with the database, however I an unsure as to when I should have a different DBContext. Currently, I have a separate ...
4
votes
1answer
868 views

DbSet<T> IncludeAll method

The Problem As an ASP.NET MVC4 developper, I'm using Entity Framework a lot. Considering performance I often use lazy loading for my models. ...
1
vote
1answer
255 views

Modeling a decision tree-like form

A picture says more than a thousand words, so here's a mock-up. The actual choices are different, this is just a sample. A user first has to choose between Red, Blue and Green. Upon selecting an ...
4
votes
1answer
2k views

custom System.Web.Http.AuthorizeAttribute

I've hacked together what feels like a mess for an authorize attribute to secure web api methods. The code appears to be functionaly correct; passing the unit tests in place. The code has me worried ...
2
votes
1answer
122 views

How can I make this code better

I hate having almost two identical blocks do almost the exact same thing. I am working with Entity Framework 4.4.0.0 Asp.Net MVC Right now if the user is a "manager" I want to show them the entire ...
1
vote
1answer
618 views

Making a property virtual to cause EF to load the property?

I am walking through a sample MVC4 ASP.Net tutorial available on PluralSight.com, by Scott Allen. I am in a section #5, Working with Data (part 2), "Listing Reviews". This application has a database ...
2
votes
1answer
278 views

Cropping and combining two images on server

I've coded following two methods to combine images that are HTTP POSTed to the server: ...
-1
votes
1answer
694 views

ASP.NET MVC 4 Shopping Cart - Cannot update shopping car items using JQuery , Ajax, jSON, jGrid [closed]

I have this code in a C# MVC 4 VS2012 project. I need to be able to update the shopping cart with jSON data using JQuery/AJAX, i'm using jqGrid to display the data and pulling the shopping cart items ...
1
vote
0answers
146 views

Best practices in implementing service methods [closed]

Consider the following architecture: ASP.NET MVC Application having controllers which depend on service classes (MembershipService, EmailService etc.) which in turn depend on data access context ...
7
votes
1answer
2k views

passing a selectlist to the view based on database models from viewmodel is a MVC anti-pattern?

We need to select a model reference from a view. To do this we need to add a dropdownlistfor. this is based on a selectlist containing database models. passing selectlists by viewbag this solves our ...
1
vote
1answer
292 views

What should I do to improve my first MVC 4 application built with C#

I've started learning .NET with MVC 4 in C# and I built a basic application to display records from a MySQL database. It's incredibly basic, but it's the best I could come up with being a complete ...
2
votes
0answers
96 views

PBKDF2 Authorization first go, is this optimal?

I've discovered that using hashed passwords with salts is much better idea than MD5/SHA256 so I'm not hashing them with PBKDF2. However I'm wondering if this is correct approach to authorize my user. ...
1
vote
1answer
193 views

How to dynamically Generate Sort strings for Data Layer from Controller

I need help refactoring this code to dynamically generate a sort string that I can send to my data layer so that my database does the sorting instead of it happening in memory. I am using MVC4 with ...
0
votes
2answers
179 views

How could I make my controller a little less hideous?

I have a controller. It functions as follows: A user imports a file and decides whether the files contents contain new entries to be placed into a database, or existing entries entries to be updated. ...
0
votes
1answer
277 views

Products table or Products + attributes when using EF + MVC 4 [closed]

What I need to build is a web application that maintains and shows products. A product has a lot of attributes, some that will be changed or added during the next year. I have 2 options for designing ...
6
votes
1answer
2k views

Can someone review my AutoFac, NHibernate & ASP.NET Web API integration?

I've recently been learning (and struggling with) integrating AutoFac, NHibernate & ASP.NET Web API. I have found several tutorials with code that did not work as anticipated but managed to ...