add steps to numbers; remove constants
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
namespace zero.Configuration;
|
||||
|
||||
public static partial class Constants
|
||||
{
|
||||
public const string ErrorFieldNone = "__zero_no_field";
|
||||
|
||||
public static partial class Auth
|
||||
{
|
||||
public const string SystemUser = "system";
|
||||
public const string DefaultScheme = "zeroScheme";
|
||||
public const string BackofficeDisplayName = "Zero Backoffice";
|
||||
public const string BackofficeScheme = "zeroBackoffice";
|
||||
public const string BackofficeCookieName = "zero.be.session";
|
||||
public const string DefaultCookieName = "zero.session";
|
||||
}
|
||||
|
||||
public static partial class Database
|
||||
{
|
||||
public const string ReservationPrefix = "zero.";
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public static class ResultExtensions
|
||||
public static Result AddError(this Result origin, string message)
|
||||
{
|
||||
origin.IsSuccess = false;
|
||||
origin.Errors.Add(new(Constants.ErrorFieldNone, message));
|
||||
origin.Errors.Add(new("__zero_no_field", message));
|
||||
return origin;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,6 @@ public partial class ZeroUserStore<TUser> :
|
||||
return IdentityResult.Failed(errors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the Raven compare/exchange key for this user.
|
||||
/// This should be unique within the store, otherwise you can't create users with the same email in different stores.
|
||||
/// </summary>
|
||||
protected virtual string GetReservationKey(TUser user) => Constants.Database.ReservationPrefix + typeof(TUser) + ':' + user.Email;
|
||||
|
||||
/// <summary>
|
||||
/// Whether an email is already reserved
|
||||
/// </summary>
|
||||
|
||||
@@ -30,6 +30,11 @@ public class Number : ZeroEntity
|
||||
/// </summary>
|
||||
public int MinLength { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// How far to increase
|
||||
/// </summary>
|
||||
public int Step { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Store current counters
|
||||
/// </summary>
|
||||
|
||||
@@ -12,4 +12,6 @@ public class NumberOptionsItem
|
||||
public long StartNumber { get; set; } = 1;
|
||||
|
||||
public int MinLength { get; set; } = 1;
|
||||
|
||||
public int Step { get; set; } = 1;
|
||||
}
|
||||
|
||||
@@ -6,14 +6,10 @@ public class NumberValidator : ZeroValidator<Number>
|
||||
{
|
||||
public NumberValidator()
|
||||
{
|
||||
//if (ctx.Context == null)
|
||||
//{
|
||||
// throw new ArgumentNullException("ctx.Context", "NumberValidator requires access to ");
|
||||
//}
|
||||
|
||||
RuleFor(x => x.Template).NotEmpty().Length(2, 60);
|
||||
RuleFor(x => x.Template).Must(x => x != null && x.Contains("{number}")).WithMessage("@shop.number.errors.invalid_template");
|
||||
RuleFor(x => x.Template).Must(x => x != null && x.Contains("{number}"));
|
||||
RuleFor(x => x.StartNumber).GreaterThanOrEqualTo(0);
|
||||
RuleFor(x => x.MinLength).ExclusiveBetween(1, 32);
|
||||
RuleFor(x => x.Step).GreaterThanOrEqualTo(1);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class Numbers : INumbers
|
||||
// calculate new value
|
||||
bool hasValue = counter.Count != 0;
|
||||
long oldValue = hasValue ? counter.Count : number.StartNumber;
|
||||
long newValue = oldValue + (hasValue ? 1 : 0);
|
||||
long newValue = oldValue + (hasValue ? number.Step : 0);
|
||||
|
||||
// increment the value and store it in database
|
||||
if (store)
|
||||
@@ -176,7 +176,8 @@ public class Numbers : INumbers
|
||||
Id = id,
|
||||
Template = options.Template,
|
||||
StartNumber = options.StartNumber,
|
||||
MinLength = options.MinLength
|
||||
MinLength = options.MinLength,
|
||||
Step = options.Step
|
||||
};
|
||||
|
||||
await Db.Create(number);
|
||||
@@ -200,6 +201,11 @@ public class Numbers : INumbers
|
||||
number.MinLength = options.MinLength;
|
||||
changed = true;
|
||||
}
|
||||
if (!number.Step.Equals(options.Step))
|
||||
{
|
||||
number.Step = options.Step;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user