Created
September 18, 2012 05:41
-
-
Save codeimpossible/3741467 to your computer and use it in GitHub Desktop.
Found some old controller/service code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ElmahHandleError] | |
public partial class ProjectsController : Controller | |
{ | |
private IProjectService _projectService = null; | |
public ProjectsController () : this( null, null ) { } | |
public ProjectsController ( IProjectService projectService ) | |
{ | |
_projectService = projectService; | |
} | |
public virtual ActionResult Index () | |
{ | |
var projects = _projectService.AllProjects().OrderByDescending( p => p.CreatedOn ).Take( 5 ).ToList(); | |
var model = new ProjectDashboardViewModel() { Projects = projects }; | |
return View( model ); | |
} | |
// ... SNIP ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProjectService : IProjectService | |
{ | |
IRepository _repository; | |
public ProjectService ( IRepository repository = null ) | |
{ | |
_repository = repository; | |
} | |
public IQueryable<Project> AllProjects () | |
{ | |
return _repository.All<Project>(); | |
} | |
public Project GetProject ( int id ) | |
{ | |
return _repository.First<Project>( p => p.ProjectId == id ); | |
} | |
public bool SaveProject ( Project project ) | |
{ | |
return _repository.Save<Project>( project ) != null; | |
} | |
public Project CreateProject ( Project project ) | |
{ | |
project.CreatedOn = DateTime.Now; | |
using ( _repository ) | |
{ | |
var savedproject = _repository.Insert<Project>( project ); | |
_repository.CommitAll(); | |
return savedproject; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment