Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

49 lines
1.5 KiB

// ==========================================================================
// GuardAsset.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using Squidex.Domain.Apps.Entities.Assets.Commands;
using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Entities.Assets.Guards
{
public static class GuardAsset
{
public static void CanRename(RenameAsset command, string oldName)
{
Guard.NotNull(command, nameof(command));
Validate.It(() => "Cannot rename asset.", error =>
{
if (string.IsNullOrWhiteSpace(command.FileName))
{
error(new ValidationError("Name must be defined.", nameof(command.FileName)));
}
if (string.Equals(command.FileName, oldName))
{
error(new ValidationError("Name is equal to old name.", nameof(command.FileName)));
}
});
}
public static void CanCreate(CreateAsset command)
{
Guard.NotNull(command, nameof(command));
}
public static void CanUpdate(UpdateAsset command)
{
Guard.NotNull(command, nameof(command));
}
public static void CanDelete(DeleteAsset command)
{
Guard.NotNull(command, nameof(command));
}
}
}