Posted on 18/09/2015 22:43:39
Thanks guys, that all makes a lot of sense. I decided to go with the number of seconds since today as that's a small enough number for the next few years to read out loud over a phone. In addition, the chance of two people submitting on the same time are relatively small, and it wouldn't be a big deal if once in a while two people would end up with the same ID anyway.
Is there a sample of the Number API somewhere? I tried this:
return Dynamicweb.eCommerce.Common.NumberGenerator.GetNumber("UniqueFormId");
but that always gives me the same number: 0 and doesn't save the result in the database. I tried working with the Number class but couldn't figure out how to do it. XML docs like "Froms the type" on a method called FromType doesn't make it any easier ;-) I assume the very first time I need to create a new Number, set some properties and save it. And then subsequently call the static GetNumber method? I tried something like this:
internal static List<string> ExistingNumbers = new List<string>();
internal string ProvideUniqueNumber(string type, string prefix)
{
if (!ExistingNumbers.Contains(type))
{
var number = Number.getNumbers(true).FirstOrDefault(x => x.ID == type + prefix);
if (number == null)
{
number = new Number
{
ID = type + prefix,
Add = 1,
Counter = 1,
Description = string.Format("Gets unique numbers for {0}", type),
Editable = true,
Prefix = prefix,
Type = type
};
number.Save(number.ID); // also tried number.Save();
ExistingNumbers.Add(type);
}
}
return NumberGenerator.GetNumber(type + prefix);
}
However, the number is never saved in EcomNumbers and GetNumber keeps returning 0.
Thanks,
Imar