public static String CreateUniqueInvoiceNumber() { String result = String.Empty; try { result = String.Format( "{0}{1}{2}", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), NumberGenerator.GetNext(NumberGenerator.GeneratorNames.Invoices).ToString()); } catch (Exception ex) { throw new Exception("Invoice numer could not be generated", ex); } return(result); }
public static void GenerateAutoTrackingNumber() { UniqueCodeSection.PerformInMutex($"TRACK{nameof(GenerateAutoTrackingNumber)}", () => { var allMailingsWithoutTrackingNumber = MyDataContext.Default.Mailings .Where(runner => runner.ShippingMethod == ShippingMethods.DeutschePost) .Where(runner => runner.TrackingNumber == null || runner.TrackingNumber == String.Empty) .ToList(); foreach (var runner in allMailingsWithoutTrackingNumber) { Int32 trackingNumer = NumberGenerator.GetNext(NumberGenerator.GeneratorNames.TrackingNumbers); runner.TrackingNumber = String.Format("{0} {1}", "cheap ship", trackingNumer); runner.MustSyncTrackingNumber = true; } Models.MyDataContext.Default.SaveChanges(); }); }