Questions tagged [asp.net-mvc]
Model-View-Controller for the ASP.NET framework
237
questions
47
votes
2
answers
100k
views
Unit of Work and Repository with Entity Framework 6
Based on the reply of this question I have created the following code. I need to check whether it's good or not.
Here is my entity class:
...
24
votes
4
answers
33k
views
How to write elegant conditional bits of markup in Razor views?
Suppose the following model:
public class ViewBookModel
{
public string Title { get; set; }
public string Subtitle { get; set; }
}
I'm currently ...
23
votes
3
answers
13k
views
Returning status codes from business layer
This is what I've been doing so far in my business layer to return error messages to the user.
...
17
votes
1
answer
284
views
Naming for unit tests for controller to edit posts
I am relatively new to TDD and am trying to adopt better names for my tests.
I wrote the following tests abruptly and have since refactored them to the best of my ability, but despite my best ...
15
votes
2
answers
39k
views
Unit of work + repository + service layer with dependency injection
I am designing a web application and a windows service and want to use the unit of work + repository layer in conjunction with a service layer, and I am having some trouble putting it all together so ...
14
votes
2
answers
5k
views
Repository and Controller tests
Lately I have been researching how to best unit test an EF repository and given a properly tested repository, what to test in the controller.
My research did not reveal many sound examples or ...
13
votes
1
answer
41k
views
Error Handling - Controller's OnException and Application_Error
I'm pretty new to MVC. Below is the code that I have added to an existing MVC 5 application. The code is using log4net to log any run-time error/exception.
NOTE: I could override ...
13
votes
1
answer
11k
views
Unit of Work (UoW) pattern with ADO.NET
I'm trying to implement the UoW pattern using ADO.NET and this is what I've achieved so far:
The IUnitOfWork Interface:
...
12
votes
1
answer
38k
views
Unit testing with dependency injection and MOQ
I'm just learning how dependency injection and mocking work, but I'd like some feedback on how I'm setting up a couple of tests. I can get them to pass, but I'm not sure this is all I need.
This is ...
11
votes
1
answer
696
views
Command-query segregation principle for an authenticator
The Authenticate method violates the command-query segregation principle, right? How can I adhere to the command-query segregation principle here?
...
10
votes
1
answer
57k
views
MVC binding list of values to checkboxlist in an efficient way
I have this code which generates and shows list of selectable items that user can post to controller in order to save into database.
Model looks like this:
...
10
votes
1
answer
183
views
ASP controller for tracking equipment
This was originally posted here. I'm hoping Code Review will be a little more helpful in giving me a concrete direction.
I've been working on a project based off of this tutorial.
Unfortunately, ...
10
votes
2
answers
4k
views
Feature-based authorization
Feature-based authorization
It seems to me that if you rely on roles to authorize a web application it makes it very difficult to render UI or code based on a set of features. This means that each ...
10
votes
1
answer
564
views
Checkers Board Creator
A year or so ago, I wrote a checkers game for the Universal Windows Platform. Now, I wrote a web-based version of it hosted at http://checkerstreasury.azurewebsites.net. This is the first of a series ...
9
votes
3
answers
848
views
Creating a round robin MySQL connection manager
Background
I am working on an e-commerce website, my web server is written in ASP.NET MVC (C#, EF6) and I am using 3 instances of MySQL DB. These DBs are in a cluster (Galera Cluster) and they are ...
8
votes
4
answers
4k
views
DDD Architecture for an e-commerce website (uploading images)
Problem Description
I am working on an e-commerce website, when a user wants to sell a product, he would open the product page and he can upload up to 12 photos:
Image Upload Process
This is the ...
8
votes
3
answers
2k
views
Implementing IDisposable for an Excel class
I am developing a class (in a C# MVC 5 project) that originally had a using block within a single method, and it got to be very huge after placing formatting ...
8
votes
1
answer
12k
views
MVC 5 & EF 6 - Repository & Unit of Work Pattern
I have been looking through Code Review on the subject of Unit of Work and Repository patterns and realised that my implementation appears to provide very similar functionality but in reverse class ...
7
votes
2
answers
2k
views
ViewModel creator design
I am trying to move some logic outside my controller for creating my view models for the view.
I have a lot of queries to fire to make sure the complete view model is ready, so to keep my ...
7
votes
2
answers
378
views
Refactoring Methods With Conditionals
I have always suffered with too many conditionals in some of my methods. The following is a pseudocode/skeleton of one of my method like that:
...
7
votes
1
answer
310
views
Somewhat esoteric if statement in a paginated feed
I am working on the home page of a website that will have a paginated feed (much like a blog's home page).
One of the requirements is that when a user navigates to a non-existent page, he or she will ...
7
votes
2
answers
1k
views
Validation for a CQS system that throws an exception
I've been reading that exceptions should only be for something "exceptional" and not used to control the flow of a program. However, with a CQS implementation, this seems impossible unless I start ...
7
votes
1
answer
5k
views
Helper for DropDownLists with extension method
Is the following helper idiomatic ASP.NET MVC? All the built-in DropDownListFor helpers only accept ...
6
votes
3
answers
4k
views
Monkeying around with Survey Monkey and Asp.Net Mvc
Intro
I've been a desktop dev for a long time now, and have never really had to monkey with web development until very recently. I have a need to do some custom integration with Survey Monkey's Api ...
6
votes
2
answers
3k
views
Expose an IDbSet<> object to overcome a limitation for LINQ's Select()
Before posting this, I have spent the past 4 days tirelessly investigating the Internet and the different Stack Exchange websites on how to correctly implement the Unit of Work pattern and Unit Test ...
6
votes
2
answers
213
views
Storing an integer counter in indexer
I've been implementing a custom internal server error page in ASP.Net MVC which will check if the current user is either an administrator or accessing the page from localhost, and if so, show them a ...
6
votes
2
answers
294
views
Repository implementation
I have a repository called PostsRepository:
...
6
votes
2
answers
12k
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 ...
6
votes
1
answer
974
views
Embedding an RSS feed into a page after it's already loaded
I'm working on reworking our website from a WYSIWYG editor to MVC. I'm all right with server side code, but complete rubbish when it comes to client side Javascript, so I'd appreciate any/all feedback....
6
votes
2
answers
7k
views
"Forgot password" functionality
I want to implement the "forgot password" functionality in Asp.Net MVC 5. Here is the code flow:
Take user email ID
Let the user enter the token received in his email inbox
If the token matches then ...
6
votes
1
answer
6k
views
Update URL with new parameter value in controller action
I have an action that takes an id as a parameter and gets the corresponding item with the help of a web service. The web service's method that returns the item will either return the item with the ...
6
votes
1
answer
79
views
Properly create and customise a web app using visual studio 2015 C# MVC template
I'm new to C# web, I want to know how to properly create a web app using
visual studio 2015 MVC templates, and being able to customise some of its code. I want to both practice C# web and clean code.....
6
votes
1
answer
7k
views
Checking locked users using Identity 2.0
I'm writing a theoretical MVC application to aid in learning more about ASP Identity 2. In real terms I'm new to ASP Identity as a whole but thought I'd jump in in this release as
it's the default ...
6
votes
3
answers
2k
views
CQS implementation with decorators
Edit
I've put all this into a nuget package and on github under "MetalCore.CQS" at https://github.com/MetalKid/MetalCore.CQS
End Edit
I've created a "framework" or more of a ...
6
votes
1
answer
15k
views
Concerned with Enums, JSON, and ASP.NET MVC
I am writing an application that uses ASP.NET MVC for its front end, and for the back end, it uses RavenDB to store data. This ...
6
votes
1
answer
631
views
Unit test for a CreateUser() method using JustMock lite
I'm new to unit testing and have created a unit test for a create user action method and it's passing the test. I'm not sure if this is the right way to unit test a create method.
This is my test ...
6
votes
1
answer
120
views
Highlight Current Link
I'm using this technique for highlighting current links (e.g. how the "Questions" link is highlighted on this very page you're looking at). I changed the code a little bit and came up with this ...
6
votes
1
answer
4k
views
Implementing HTTP Strict-Transport-Security via MVC action filter
HTTP Strict Transport Security (HSTS) is an opt-in security enhancement that is specified by a web application through the use of a special response header. Once a supported browser receives this ...
5
votes
2
answers
385
views
Getting list of daily team goals
The old code I had before was atrociously slow but after some advice and research I was able to take a 2-5 minutes run time down to about 5-30 seconds. That is acceptable, but still looking to have ...
5
votes
4
answers
2k
views
Generic Repository For Web Apps
I was developing a web app using Entity Framework 6 and MVC 5. For the data access layer, I eased the job and wrote a generic repository as following:
...
5
votes
1
answer
3k
views
Pagination implementation for a blog system
Last night I was working on a project that I've embarked upon as a learning exercise. I decided to add a pagination feature to my blog system. I made an attempt at it and got close... but I decided to ...
5
votes
3
answers
4k
views
5
votes
2
answers
207
views
Keeping data processing out of controllers
I would like to start by mentioning that I am LAMP stack guy who happens to be making my first ever .NET C# web app and I'm seeking general advises for best practices and to see how more experienced ...
5
votes
1
answer
1k
views
Combating magic strings in a web application
I'm on a quest to combat all the magic strings which tends to pile up in an ASP.NET MVC application.
All reviews will be highly appreciate but please note that:
Some of the classes contains more (...
5
votes
2
answers
19k
views
A set of Razor HTML helpers for disabling elements
I am developing a huge form with a lot of elements in it. The purpose of this form is editing one domain entity. Now, I finished developing the whole form and it just shows the bunch of text boxes, ...
5
votes
2
answers
124
views
Writing a thin navigation controller
I'm trying to achieve a thin controller, and I started out with a thin controller but over time as the project has progressed the controller has got more complex. Could you please review the following ...
5
votes
1
answer
4k
views
Is it an anti-pattern to let ViewModel fill itself from a domain object? [closed]
Let's say you have a Employees table mapped to a Employee class. Now you want to code a Edit page for general information. You need a ViewModel with all the properties you need to build the page, so ...
5
votes
2
answers
910
views
Abstracting a Password Service
I want to use Microsoft.AspNet.Identity's PasswordHasher but I don't want to pollute my Domain layer with knowledge of it. As ...
5
votes
1
answer
186
views
Displaying alert from an action
This code works great, but I think it can be reduced.
...
5
votes
1
answer
4k
views
Recurring tasks in ASP.NET MVC
I have 2 alternatives for executing recurring tasks in ASP.NET MVC.
We just need to add some code in Global.asax
First alternative:
...