Skip to content

Instantly share code, notes, and snippets.

@Fodsuk
Created August 4, 2011 14:45
Show Gist options
  • Save Fodsuk/1125320 to your computer and use it in GitHub Desktop.
Save Fodsuk/1125320 to your computer and use it in GitHub Desktop.
a tiny bit shorter
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