Created
August 4, 2011 14:45
-
-
Save Fodsuk/1125320 to your computer and use it in GitHub Desktop.
a tiny bit shorter
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using BackOffice.WebUI.Controllers.Base; | |
using Watchfinder.Commands.Marketing.Channels; | |
using Watchfinder.Reads.Marketing; | |
using Watchfinder.Reads.Marketing.Views; | |
namespace BackOffice.WebUI.Controllers.NewControllers.Marketing | |
{ | |
public class ChannelsController : ActionFilterBaseController | |
{ | |
private ChannelQueries _queries; | |
public ChannelsController() | |
{ | |
_queries = new ChannelQueries(); | |
} | |
[SystemPage(CheckPagePermissions = false)] | |
public ActionResult Index() | |
{ | |
return View(_queries.GetAllChannels()); | |
} | |
[SystemPage(CheckPagePermissions = false)] | |
public ActionResult Save(int id=0) | |
{ | |
CreateOrUpdateChannel command = (id == 0) | |
? new CreateOrUpdateChannel() | |
: ConvertViewToCommand(_queries.GetByID(id)); | |
return View(command); | |
} | |
[HttpPost] | |
[SystemPage(CheckPagePermissions = false)] | |
public ActionResult Save(CreateOrUpdateChannel command) | |
{ | |
var result = Dispatcher.Dispatch(command); | |
command = (command.ID == 0) ? command : ConvertViewToCommand(_queries.GetByID(command.ID)); | |
AddTempUnitOfWorkMessages(); | |
AddUnitOfWorkMessages(); | |
if(result.Success) | |
{ | |
return RedirectToAction("index"); | |
} | |
return View(command); | |
} | |
private CreateOrUpdateChannel ConvertViewToCommand(Channel channel) | |
{ | |
return new CreateOrUpdateChannel() | |
{ | |
ID = channel.ID, | |
Name = channel.Name, | |
Code = channel.Code, | |
Enabled = channel.Enabled | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment