Created
October 30, 2012 21:14
-
-
Save wayne-o/3983108 to your computer and use it in GitHub Desktop.
This file contains 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 AdminController : Controller | |
{ | |
private readonly IRepository<Category> repository; | |
public AdminController(IRepository<Category> repository) | |
{ | |
this.repository = repository; | |
} | |
public ViewResult Categories() | |
{ | |
var categoriesListViewModel = new CategoriesListViewModel(); | |
repository.GetAll().ForEach(x => categoriesListViewModel.Categories.Add(x)); | |
return View("Categories", categoriesListViewModel); | |
} | |
[HttpGet] | |
public ActionResult CategoriesAdd() | |
{ | |
return View("CategoriesAdd"); | |
} | |
[HttpPost] | |
[ActionName("CategoriesAdd")] | |
public ActionResult CategoriesAdd(CategoriesAddViewModel viewModel) | |
{ | |
repository.Save(new Category | |
{ | |
Id = Guid.NewGuid().ToString(), | |
Name = viewModel.CategoryName, | |
Enabled = viewModel.Enabled | |
}); | |
return RedirectToAction("Categories", "Admin"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment