Skip to content

@jbogard /ConferenceController.cs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
public class ConferenceController : Controller
{
private readonly ISession _session;
public ConferenceController(ISession session)
{
_session = session;
}
public ActionResult Index(int? minSessions)
{
minSessions = minSessions ?? 0;
var list = (from conf in _session.Query<Conference>()
where conf.SessionCount >= minSessions
select new ConferenceListModel
{
Id = conf.Id,
Name = conf.Name,
SessionCount = conf.SessionCount,
AttendeeCount = conf.AttendeeCount
}).ToArray();
return View(list);
}
public ViewResult Show(string eventName)
{
var conf = _session
.Query<Conference>()
.SingleOrDefault(c => c.Name == eventName);
var model = new ConferenceShowModel
{
Name = conf.Name,
Sessions = conf.GetSessions()
.Select(s => new ConferenceShowModel.SessionModel
{
Title = s.Title,
SpeakerFirstName = s.Speaker.FirstName,
SpeakerLastName = s.Speaker.LastName,
}).ToArray()
};
return View(model);
}
public ActionResult Edit(string eventName)
{
var conf = _session
.Query<Conference>()
.SingleOrDefault(c => c.Name == eventName);
var model = new ConferenceEditModel
{
Id = conf.Id,
Name = conf.Name,
Attendees = conf.GetAttendees()
.Select(a => new ConferenceEditModel.AttendeeEditModel
{
Id = a.Id,
FirstName = a.FirstName,
LastName = a.LastName,
Email = a.Email,
}).ToArray()
};
return View(model);
}
[HttpPost]
public ActionResult Edit(ConferenceEditModel form)
{
if (!ModelState.IsValid)
{
return View(form);
}
var conf = _session.Get<Conference>(form.Id);
conf.ChangeName(form.Name);
foreach (var attendeeEditModel in form.Attendees)
{
var attendee = conf.GetAttendee(attendeeEditModel.Id);
attendee.ChangeName(attendeeEditModel.FirstName, attendeeEditModel.LastName);
attendee.Email = attendeeEditModel.Email;
}
return this.RedirectToAction(c => c.Index(null), "Default");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.