//Methods
        #region GetNext
        public static Int32 GetNext(GeneratorNames generator)
        {
            NumberGenerator currentNumber = MyDataContext.Default.NumberGenerators.First(runner => runner.Name == generator.ToString());

            currentNumber.CurrentNumber += currentNumber.StepWidth;
            MyDataContext.Default.SaveChanges();
            return(currentNumber.CurrentNumber);
        }
        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);
        }
Esempio n. 3
0
        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();
            });
        }