Add constraint to instruction set.

This commit is contained in:
2019-05-19 22:24:00 +01:00
parent 2785155680
commit 3264c73da1
3 changed files with 10 additions and 1 deletions

View File

@@ -30,6 +30,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
namespace Cicm.Database.Models
{
@@ -42,6 +43,7 @@ namespace Cicm.Database.Models
[Required]
[StringLength(45)]
[Remote("VerifyUnique", "InstructionSets", "Admin")]
public string Name { get; set; }
public virtual ICollection<Processor> Processors { get; set; }

View File

@@ -28,6 +28,7 @@
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
using System;
using System.Linq;
using System.Threading.Tasks;
using Cicm.Database.Models;
@@ -147,5 +148,11 @@ namespace cicm_web.Areas.Admin.Controllers
{
return _context.InstructionSets.Any(e => e.Id == id);
}
[AcceptVerbs("Get", "Post")]
public IActionResult VerifyUnique(string name) =>
_context.InstructionSets.Any(i => string.Equals(i.Name, name, StringComparison.InvariantCultureIgnoreCase))
? Json("Instruction set already exists.")
: Json(true);
}
}

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>3.0.99.518</Version>
<Version>3.0.99.520</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>