PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 2ms 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
 1using System.Collections.Generic;
 2using System.Linq;
 3using System.Web.Mvc;
 4using Bifrost.Commands;
 5using Bifrost.Query;
 6using Bifrost.Samples.Shop.Domain.Campaigns;
 7
 8namespace Bifrost.Samples.Shop.Mvc.Features.Campaigns
 9{
10	public class CampaignsController : Controller
11	{
12		private readonly IQueryRepository<Query.Campaigns.Campaign> _repository;
13		private readonly ICommandCoordinator _coordinator;
14
15		public CampaignsController(
16			IQueryRepository<Query.Campaigns.Campaign> repository,
17			ICommandCoordinator coordinator)
18		{
19			_repository = repository;
20			_coordinator = coordinator;
21		}
22
23
24		public ActionResult New()
25		{
26			return View("New");
27		}
28
29		public ActionResult Create(CreateNewCampaign createNewCampaign)
30		{
31			_coordinator.Handle(createNewCampaign);
32			return Index();
33		}
34
35		public ActionResult Index()
36		{
37			var query = from c in _repository.Query
38						select c;
39
40			var campaigns = new List<Campaign>();
41			foreach( var campaign in query )
42			{
43				campaigns.Add(new Campaign
44				              	{
45				              		Name = campaign.Name,
46				              		Status = campaign.Status.ToString(),
47				              		Title = campaign.Title,
48									Zone = campaign.Zone.Name
49
50				              	});
51
52			}
53
54			return View("List", campaigns);
55		}
56
57	}
58}