Esempio n. 1
0
        private void SaveUniverse(IUniverseCreated command, UniverseDbObject lastUniverse, out UniverseDbObject nextUniverse, ref List <UniverseDbObject> universes)
        {
            nextUniverse = null;
            if (lastUniverse == null)
            {
                nextUniverse = MapEntity(command);
                AddOrUpdate(ref universes, nextUniverse); // "Add"
                return;
            }

            if (command.StartDate < lastUniverse.StartDate.Date)
            {
                throw new DataSyncException(DataSyncErrorCode.Universe_StartDateLessThanPredecessors,
                                            "universe start date(" + command.StartDate + ") should be greater than or equal to existing universe start date(" +
                                            lastUniverse.StartDate + "). Sales area:" + command.SalesArea + ", Demographic:" + command.Demographic);
            }

            if (command.StartDate == lastUniverse.StartDate.Date) //"update/overwrite";
            {
                lastUniverse.EndDate       = command.EndDate;
                lastUniverse.UniverseValue = command.UniverseValue;
                nextUniverse = lastUniverse;
                AddOrUpdate(ref universes, lastUniverse);
                return;
            }

            if (command.StartDate > lastUniverse.StartDate && command.EndDate <= lastUniverse.EndDate)
            {
                throw new DataSyncException(DataSyncErrorCode.Universe_DateRangeOverlapsPredecessors,
                                            "universe start and end date range should not fully overlap with existing universe start date(" +
                                            lastUniverse.StartDate + ") end date (" + lastUniverse.EndDate + "). Sales area:" + command.SalesArea + ", Demographic:" + command.Demographic);
            }

            if (command.StartDate == lastUniverse.EndDate.AddDays(1).Date)
            {
                nextUniverse = MapEntity(command);
                AddOrUpdate(ref universes, nextUniverse); // "Add"
                return;
            }

            if (command.StartDate > lastUniverse.EndDate.AddDays(1).Date)
            {
                throw new DataSyncException(DataSyncErrorCode.Universe_GapMoreThan1Day,
                                            "Universe start date should not be greater than(" + lastUniverse.EndDate.AddDays(1).Date +
                                            "). Sales area:" + command.SalesArea + ", Demographic:" + command.Demographic);
            }

            if (command.StartDate > lastUniverse.StartDate.Date && command.StartDate <= lastUniverse.EndDate.Date &&
                command.EndDate > lastUniverse.EndDate.Date
                ) //   "Add it as new and also update the existing start date";
            {
                nextUniverse = MapEntity(command);
                AddOrUpdate(ref universes, nextUniverse);

                lastUniverse.EndDate = command.StartDate.AddDays(-1).Date;
                AddOrUpdate(ref universes, lastUniverse);
            }
        }
Esempio n. 2
0
 private static void AddOrUpdate(ref List <UniverseDbObject> universes, UniverseDbObject universe)
 {
     _ = universes.RemoveAll(_ => _.Id.Equals(universe.Id));
     universes.Add(universe);
 }