vgquotes/Src/VideoGameQuotes.Web/Controllers/SystemController.cs

53 lines
1.7 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
2011-02-23 21:53:51 +00:00
using Portoa.Util;
using Portoa.Web.Controllers;
using VideoGameQuotes.Api;
using VideoGameQuotes.Web.Models;
using VideoGameQuotes.Web.Security;
using VideoGameQuotes.Web.Services;
namespace VideoGameQuotes.Web.Controllers {
public class SystemController : Controller {
private readonly ISystemService systemService;
public SystemController(ISystemService systemService) {
this.systemService = systemService;
}
2011-02-23 21:53:51 +00:00
[HttpPost, VerifyUser(Group = UserGroup.Admin)]
public JsonResult Edit(EditSystemModel model) {
if (model.SystemId < 1) {
ModelState.AddModelError("SystemId", "Invalid system ID");
}
if (!ModelState.IsValid) {
return Json(this.CreateJsonErrorResponse("Some errors occurred"));
}
var system = systemService.FindById(model.SystemId);
system.Name = model.SystemName;
system.Abbreviation = model.SystemAbbreviation;
system.ReleaseDate = model.SystemReleaseDate;
system = systemService.Save(system);
return Json(this.CreateJsonResponse(data: system.ToDto()));
}
[HttpPost, VerifyUser]
2011-02-23 21:53:51 +00:00
public ActionResult Create(EditSystemModel model) {
if (!ModelState.IsValid) {
return Json(this.CreateJsonErrorResponse("Some errors occurred"));
}
if (systemService.FindByNameOrAbbreviation(model.SystemName, model.SystemAbbreviation).Any()) {
return Json(this.CreateJsonResponse("A system with that name or abbreviation already exists."));
}
var system = systemService.Save(new GamingSystem { Abbreviation = model.SystemAbbreviation, Name = model.SystemName, ReleaseDate = model.SystemReleaseDate });
return Json(this.CreateJsonResponse(data: system.ToDto()));
}
}
}