예제 #1
0
 public Model.IQueue Put(string id, [FromBody] Model.IQueue value)
 {
     return(new Model.Queue()
     {
         ParkingCard = id
     }
            .Put());
 }
예제 #2
0
        /// <summary>Включает элемент в очередь, транзакцией</summary>
        /// <param name="entity">Элемент</param>
        /// <returns>Успех операции</returns>
        internal static bool EnQueueTran(Model.IQueue entity)
        {
            lock (Locker)
            {
                if (entity == null)
                {
                    return(false);
                }

                using (Repository repository = new Repository())
                {
                    using (var tran = repository.Database.BeginTransaction(TranIsolationLevel))
                    {
                        // проверка на дубли:
                        if (repository.Queue.Find(entity.ParkingCard) != null)
                        {
                            return(false);
                        }

                        // добавление элемента в очередь:
                        repository.Queue.Add(new Queue()
                        {
                            Input       = DateTime.Now,
                            ParkingCard = entity.ParkingCard
                        });
                        repository.SaveChanges();

                        // отправка всех изменений модели в БД:
                        tran.Commit();
                    }
                }

                Model.Notifier.OnQueueChanged(new QueueChangedEventArgs()
                {
                    Reason = QueueChangedEnum.EnQueue,
                    Queue  = new Model.Queue().Get(ViewLimitParam)
                });

                return(true);
            }
        }
예제 #3
0
        /// <summary>Исключает элемент из очереди, транзакцией</summary>
        /// <param name="entity">Элемент</param>
        /// <param name="reason">Причина исключения из очереди</param>
        /// <param name="extRepository">Экземпляр репозитория при внешней транзакции</param>
        /// <param name="extTransaction">Экземпляр транзакции при внешней транзакции</param>
        /// <returns>Успех операции</returns>
        internal static bool DeQueueTran(Model.IQueue entity, OutputReasonEnum reason,
                                         Repository extRepository = null, DbContextTransaction extTransaction = null)
        {
            lock (Locker)
            {
                if (entity == null)
                {
                    return(false);
                }

                using (Repository repository = extRepository ?? new Repository())
                {
                    using (var tran = extTransaction ?? repository.Database.BeginTransaction(TranIsolationLevel))
                    {
                        // необходимо убедиться, что элемент существует в текущей транзакции:
                        var entityTran = repository.Queue.Find(entity.ParkingCard);
                        if (entityTran == null)
                        {
                            return(false);
                        }

                        var outputReason = repository.OutputReason
                                           .First(t => t.Code == reason.ToString());

                        // копирование элемента в историю:
                        if (repository.QueueHistory.Find(entity.Input, entity.ParkingCard) == null)
                        {
                            repository.QueueHistory.Add(new QueueHistory()
                            {
                                Input         = entity.Input,
                                Output        = DateTime.Now,
                                ParkingCard   = entity.ParkingCard,
                                Rotation      = entity.Rotation,
                                RotationStart = entity.RotationStart,
                                Position      = entity.Position,
                                OutputReason  = outputReason
                            });
                        }

                        // удаление элемента из очереди:
                        repository.Queue.Remove(entityTran);

                        // сохранение всех изменений модели:
                        repository.SaveChanges();

                        // пересчёт фиксированных позиций:
                        switch (reason)
                        {
                        case OutputReasonEnum.Rotation:
                            break;

                        case OutputReasonEnum.Peek:
                            FixedPositionsMoveUp(repository);
                            break;

                        case OutputReasonEnum.Vip:
                        case OutputReasonEnum.Time:
                            if (entity.Position <= RotationPlaceParam)
                            {
                                FixedPositionsMoveUp(repository);
                            }
                            break;
                        }

                        // отправка всех изменений модели в БД:
                        tran.Commit();
                    }
                }

                Model.Notifier.OnQueueChanged(new QueueChangedEventArgs()
                {
                    Reason = QueueChangedEnum.DeQueue,
                    Queue  = new Model.Queue().Get(ViewLimitParam)
                });

                return(true);
            }
        }