30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
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 PublisherController : Controller {
|
|
private readonly IPublisherService publisherService;
|
|
|
|
public PublisherController(IPublisherService publisherService) {
|
|
this.publisherService = publisherService;
|
|
}
|
|
|
|
[HttpPost, VerifyUser]
|
|
public ActionResult Create(CreatePublisherModel model) {
|
|
if (!ModelState.IsValid) {
|
|
return Json(this.CreateJsonErrorResponse("Some errors occurred."));
|
|
}
|
|
|
|
if (publisherService.FindByName(model.PublisherName) != null) {
|
|
return Json(this.CreateJsonResponse("A publisher with that name already exists."));
|
|
}
|
|
|
|
var publisher = publisherService.Save(new Publisher { Name = model.PublisherName, Website = model.PublisherWebsite });
|
|
return Json(this.CreateJsonResponse(data: publisher.ToDto()));
|
|
}
|
|
}
|
|
} |