32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
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;
|
|
}
|
|
|
|
[HttpPost, VerifyUser]
|
|
public ActionResult Create(CreateSystemModel 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()));
|
|
}
|
|
}
|
|
} |