PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Samples/Shop/Bifrost.Samples.Shop.Mvc/Features/Campaigns/CampaignsController.cs

#
C# | 58 lines | 47 code | 11 blank | 0 comment | 0 complexity | b5e9f96cb71019d2e8395193f4deee49 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Web.Mvc;
  4. using Bifrost.Commands;
  5. using Bifrost.Query;
  6. using Bifrost.Samples.Shop.Domain.Campaigns;
  7. namespace Bifrost.Samples.Shop.Mvc.Features.Campaigns
  8. {
  9. public class CampaignsController : Controller
  10. {
  11. private readonly IQueryRepository<Query.Campaigns.Campaign> _repository;
  12. private readonly ICommandCoordinator _coordinator;
  13. public CampaignsController(
  14. IQueryRepository<Query.Campaigns.Campaign> repository,
  15. ICommandCoordinator coordinator)
  16. {
  17. _repository = repository;
  18. _coordinator = coordinator;
  19. }
  20. public ActionResult New()
  21. {
  22. return View("New");
  23. }
  24. public ActionResult Create(CreateNewCampaign createNewCampaign)
  25. {
  26. _coordinator.Handle(createNewCampaign);
  27. return Index();
  28. }
  29. public ActionResult Index()
  30. {
  31. var query = from c in _repository.Query
  32. select c;
  33. var campaigns = new List<Campaign>();
  34. foreach( var campaign in query )
  35. {
  36. campaigns.Add(new Campaign
  37. {
  38. Name = campaign.Name,
  39. Status = campaign.Status.ToString(),
  40. Title = campaign.Title,
  41. Zone = campaign.Zone.Name
  42. });
  43. }
  44. return View("List", campaigns);
  45. }
  46. }
  47. }