New Angular based web version #1
@@ -201,6 +201,14 @@ export class EditCarComponent implements OnInit {
|
|||||||
'Die Anwendung scheint falsche Daten an den Server zu senden.',
|
'Die Anwendung scheint falsche Daten an den Server zu senden.',
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case error.status === 409:
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'warn',
|
||||||
|
summary: 'Konflikt',
|
||||||
|
detail:
|
||||||
|
'Es existiert bereits ein Auto mit diesem Namen. Bitte wähle einen anderen Namen.',
|
||||||
|
});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.error(error);
|
console.error(error);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Vegasco.Server.Api.Authentication;
|
using Vegasco.Server.Api.Authentication;
|
||||||
using Vegasco.Server.Api.Common;
|
using Vegasco.Server.Api.Common;
|
||||||
using Vegasco.Server.Api.Persistence;
|
using Vegasco.Server.Api.Persistence;
|
||||||
@@ -19,7 +20,8 @@ public static class CreateCar
|
|||||||
.WithTags("Cars")
|
.WithTags("Cars")
|
||||||
.WithDescription("Creates a new car")
|
.WithDescription("Creates a new car")
|
||||||
.Produces<Response>(201)
|
.Produces<Response>(201)
|
||||||
.ProducesValidationProblem();
|
.ProducesValidationProblem()
|
||||||
|
.Produces(409);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Validator : AbstractValidator<Request>
|
public class Validator : AbstractValidator<Request>
|
||||||
@@ -59,10 +61,18 @@ public static class CreateCar
|
|||||||
|
|
||||||
Car car = new()
|
Car car = new()
|
||||||
{
|
{
|
||||||
Name = request.Name,
|
Name = request.Name.Trim(),
|
||||||
UserId = userId
|
UserId = userId
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var isDuplicate = await dbContext.Cars
|
||||||
|
.AnyAsync(x => x.Name.ToUpper() == request.Name.ToUpper(), cancellationToken);
|
||||||
|
|
||||||
|
if (isDuplicate)
|
||||||
|
{
|
||||||
|
return TypedResults.Conflict();
|
||||||
|
}
|
||||||
|
|
||||||
await dbContext.Cars.AddAsync(car, cancellationToken);
|
await dbContext.Cars.AddAsync(car, cancellationToken);
|
||||||
await dbContext.SaveChangesAsync(cancellationToken);
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Vegasco.Server.Api.Authentication;
|
using Vegasco.Server.Api.Authentication;
|
||||||
using Vegasco.Server.Api.Common;
|
using Vegasco.Server.Api.Common;
|
||||||
using Vegasco.Server.Api.Persistence;
|
using Vegasco.Server.Api.Persistence;
|
||||||
@@ -19,7 +20,8 @@ public static class UpdateCar
|
|||||||
.WithDescription("Updates a car by ID")
|
.WithDescription("Updates a car by ID")
|
||||||
.Produces<Response>()
|
.Produces<Response>()
|
||||||
.ProducesValidationProblem()
|
.ProducesValidationProblem()
|
||||||
.Produces(404);
|
.Produces(404)
|
||||||
|
.Produces(409);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Validator : AbstractValidator<Request>
|
public class Validator : AbstractValidator<Request>
|
||||||
@@ -53,7 +55,15 @@ public static class UpdateCar
|
|||||||
return TypedResults.NotFound();
|
return TypedResults.NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
car.Name = request.Name;
|
var isDuplicate = await dbContext.Cars
|
||||||
|
.AnyAsync(x => x.Name.ToUpper() == request.Name.ToUpper(), cancellationToken);
|
||||||
|
|
||||||
|
if (isDuplicate)
|
||||||
|
{
|
||||||
|
return TypedResults.Conflict();
|
||||||
|
}
|
||||||
|
|
||||||
|
car.Name = request.Name.Trim();
|
||||||
await dbContext.SaveChangesAsync(cancellationToken);
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
Response response = new(car.Id.Value, car.Name);
|
Response response = new(car.Id.Value, car.Name);
|
||||||
|
|||||||
Reference in New Issue
Block a user