Inheritance: IdentifiedEntity
コード例 #1
0
ファイル: Schedule.cs プロジェクト: breslavsky/queue
        public async Task<DTO.Schedule> AddDefaultExceptionSchedule(DateTime scheduleDate)
        {
            return await Task.Run(() =>
            {
                CheckPermission(UserRole.Administrator, AdministratorPermissions.DefaultSchedule);

                using (var session = SessionProvider.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    scheduleDate = scheduleDate.Date;

                    var schedule = session.CreateCriteria<DefaultExceptionSchedule>()
                        .Add(Expression.Eq("ScheduleDate", scheduleDate))
                        .SetMaxResults(1)
                        .UniqueResult<DefaultExceptionSchedule>();
                    if (schedule == null)
                    {
                        var dayOfWeek = scheduleDate.DayOfWeek;

                        var template = session.CreateCriteria<DefaultWeekdaySchedule>()
                            .Add(Expression.Eq("DayOfWeek", dayOfWeek))
                            .SetMaxResults(1)
                            .UniqueResult<DefaultWeekdaySchedule>();

                        schedule = new DefaultExceptionSchedule()
                        {
                            ScheduleDate = scheduleDate,
                            StartTime = template.StartTime,
                            FinishTime = template.FinishTime,
                            IsWorked = template.IsWorked,
                            LiveClientInterval = template.LiveClientInterval,
                            Intersection = template.Intersection,
                            MaxClientRequests = template.MaxClientRequests,
                            RenderingMode = template.RenderingMode,
                            EarlyStartTime = template.EarlyStartTime,
                            EarlyFinishTime = template.EarlyFinishTime,
                            EarlyReservation = template.EarlyReservation,
                            EarlyClientInterval = template.EarlyClientInterval,
                            MaxOnlineOperators = template.MaxOnlineOperators,
                            OnlineOperatorsOnly = template.OnlineOperatorsOnly
                        };
                        session.Save(schedule);

                        foreach (var r in session.CreateCriteria<ServiceRendering>()
                                                     .Add(Expression.Eq("Schedule", template))
                                                     .AddOrder(Order.Asc("ServiceStep"))
                                                     .AddOrder(Order.Desc("Priority"))
                                                     .List<ServiceRendering>().ToArray())
                        {
                            var rendering = new ServiceRendering()
                            {
                                Schedule = schedule,
                                Operator = r.Operator,
                                Mode = r.Mode,
                                Priority = r.Priority
                            };

                            session.Save(rendering);
                        }
                    }

                    var todayQueuePlan = QueueInstance.TodayQueuePlan;
                    using (var locker = todayQueuePlan.WriteLock())
                    {
                        transaction.Commit();

                        // Why?
                        //session.Refresh(schedule);

                        todayQueuePlan.Flush(QueuePlanFlushMode.ServiceSchedule);
                        todayQueuePlan.Build(DateTime.Now.TimeOfDay);
                    }

                    return Mapper.Map<Schedule, DTO.Schedule>(schedule);
                }
            });
        }
コード例 #2
0
ファイル: Schedule.cs プロジェクト: breslavsky/queue
        public async Task FillServiceWeekdaySchedule(Guid serviceId, DayOfWeek targetDay)
        {
            await Task.Run(() =>
            {
                CheckPermission(UserRole.Administrator, AdministratorPermissions.Services);

                using (var session = SessionProvider.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    var service = session.Get<Service>(serviceId);
                    if (service == null)
                    {
                        throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(serviceId),
                            string.Format("Услуга [{0}] не найдена", serviceId));
                    }

                    var template = session.CreateCriteria<ServiceWeekdaySchedule>()
                        .Add(Expression.Eq("Service", service))
                        .Add(Expression.Eq("DayOfWeek", targetDay))
                        .SetMaxResults(1)
                        .UniqueResult<ServiceWeekdaySchedule>();
                    if (template == null)
                    {
                        throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(targetDay),
                            string.Format("Расписание не найдено [{0}] день недели", targetDay));
                    }

                    foreach (var day in new DayOfWeek[] {
                        DayOfWeek.Monday,
                        DayOfWeek.Tuesday,
                        DayOfWeek.Wednesday,
                        DayOfWeek.Thursday,
                        DayOfWeek.Friday,
                        DayOfWeek.Saturday})
                    {
                        if (day != targetDay)
                        {
                            var schedule = session.CreateCriteria<ServiceWeekdaySchedule>()
                                .Add(Expression.Eq("Service", service))
                                .Add(Expression.Eq("DayOfWeek", day))
                                .SetMaxResults(1)
                                .UniqueResult<ServiceWeekdaySchedule>();
                            if (schedule == null)
                            {
                                schedule = new ServiceWeekdaySchedule()
                                {
                                    Service = service,
                                    DayOfWeek = day
                                };
                            }

                            schedule.StartTime = template.StartTime;
                            schedule.FinishTime = template.FinishTime;
                            schedule.IsWorked = template.IsWorked;
                            schedule.LiveClientInterval = template.LiveClientInterval;
                            schedule.Intersection = template.Intersection;
                            schedule.MaxClientRequests = template.MaxClientRequests;
                            schedule.RenderingMode = template.RenderingMode;
                            schedule.EarlyStartTime = template.EarlyStartTime;
                            schedule.EarlyFinishTime = template.EarlyFinishTime;
                            schedule.EarlyReservation = template.EarlyReservation;
                            schedule.EarlyClientInterval = template.EarlyClientInterval;
                            schedule.MaxOnlineOperators = template.MaxOnlineOperators;
                            schedule.OnlineOperatorsOnly = template.OnlineOperatorsOnly;
                            session.Save(schedule);

                            foreach (var r in session.CreateCriteria<ServiceRendering>()
                                .Add(Expression.Eq("Schedule", schedule))
                                .List<ServiceRendering>())
                            {
                                session.Delete(r);
                            }

                            foreach (var r in session.CreateCriteria<ServiceRendering>()
                                .Add(Expression.Eq("Schedule", template))
                                .List<ServiceRendering>())
                            {
                                var rendering = new ServiceRendering()
                                {
                                    Schedule = schedule,
                                    Operator = r.Operator,
                                    Mode = r.Mode,
                                    Priority = r.Priority
                                };

                                session.Save(rendering);
                            }

                            session.Save(schedule);
                        }
                    }

                    var todayQueuePlan = QueueInstance.TodayQueuePlan;
                    using (var locker = todayQueuePlan.WriteLock())
                    {
                        transaction.Commit();

                        todayQueuePlan.Flush(QueuePlanFlushMode.ServiceSchedule);
                        todayQueuePlan.Build(DateTime.Now.TimeOfDay);
                    }
                }
            });
        }
コード例 #3
0
ファイル: Schedule.cs プロジェクト: breslavsky/queue
        public async Task<DTO.Schedule> AddServiceExceptionSchedule(Guid serviceId, DateTime scheduleDate)
        {
            return await Task.Run(() =>
            {
                CheckPermission(UserRole.Administrator, AdministratorPermissions.Services);

                using (var session = SessionProvider.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    var service = session.Get<Service>(serviceId);
                    if (service == null)
                    {
                        throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(serviceId), string.Format("Услуга [{0}] не найдена", serviceId));
                    }

                    var schedule = session.CreateCriteria<ServiceExceptionSchedule>()
                        .Add(Expression.Eq("Service", service))
                        .Add(Expression.Eq("ScheduleDate", scheduleDate))
                        .SetMaxResults(1)
                        .UniqueResult<ServiceExceptionSchedule>();
                    if (schedule == null)
                    {
                        var template = session.CreateCriteria<DefaultExceptionSchedule>()
                            .Add(Expression.Eq("ScheduleDate", scheduleDate))
                            .SetMaxResults(1)
                            .UniqueResult<Schedule>();

                        if (template == null)
                        {
                            var dayOfWeek = scheduleDate.DayOfWeek;

                            template = session.CreateCriteria<ServiceWeekdaySchedule>()
                                .Add(Expression.Eq("Service", service))
                                .Add(Expression.Eq("DayOfWeek", dayOfWeek))
                                .SetMaxResults(1)
                                .UniqueResult<Schedule>();

                            if (template == null)
                            {
                                template = session.CreateCriteria<DefaultWeekdaySchedule>()
                                    .Add(Expression.Eq("DayOfWeek", dayOfWeek))
                                    .SetMaxResults(1)
                                    .UniqueResult<Schedule>();
                            }
                        }

                        schedule = new ServiceExceptionSchedule()
                        {
                            Service = service,
                            ScheduleDate = scheduleDate,

                            StartTime = template.StartTime,
                            FinishTime = template.FinishTime,
                            IsWorked = template.IsWorked,
                            LiveClientInterval = template.LiveClientInterval,
                            Intersection = template.Intersection,
                            MaxClientRequests = template.MaxClientRequests,
                            RenderingMode = template.RenderingMode,
                            EarlyStartTime = template.EarlyStartTime,
                            EarlyFinishTime = template.EarlyFinishTime,
                            EarlyReservation = template.EarlyReservation,
                            EarlyClientInterval = template.EarlyClientInterval,
                            MaxOnlineOperators = template.MaxOnlineOperators,
                            OnlineOperatorsOnly = template.OnlineOperatorsOnly
                        };
                        session.Save(schedule);

                        foreach (var r in session.CreateCriteria<ServiceRendering>()
                                                     .Add(Expression.Eq("Schedule", template))
                                                     .List<ServiceRendering>().ToArray())
                        {
                            var rendering = new ServiceRendering()
                            {
                                Schedule = schedule,
                                Operator = r.Operator,
                                Mode = r.Mode,
                                Priority = r.Priority
                            };

                            session.Save(rendering);
                        }
                    }

                    session.Save(schedule);

                    var todayQueuePlan = QueueInstance.TodayQueuePlan;
                    using (var locker = todayQueuePlan.WriteLock())
                    {
                        transaction.Commit();

                        todayQueuePlan.Flush(QueuePlanFlushMode.ServiceSchedule);
                        todayQueuePlan.Build(DateTime.Now.TimeOfDay);
                    }

                    return Mapper.Map<Schedule, DTO.Schedule>(schedule);
                }
            });
        }
コード例 #4
0
ファイル: ServiceRendering.cs プロジェクト: breslavsky/queue
        public async Task<DTO.ServiceRendering> EditServiceRendering(DTO.ServiceRendering source)
        {
            return await Task.Run(() =>
            {
                CheckPermission(UserRole.Administrator, AdministratorPermissions.Services);

                using (var session = SessionProvider.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    ServiceRendering serviceRendering;

                    if (!source.Empty())
                    {
                        Guid serviceRenderingId = source.Id;
                        serviceRendering = session.Get<ServiceRendering>(serviceRenderingId);
                        if (serviceRendering == null)
                        {
                            throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(serviceRenderingId),
                                string.Format("Обслуживание услуги [{0}] не найдено", serviceRenderingId));
                        }
                    }
                    else
                    {
                        serviceRendering = new ServiceRendering();
                    }

                    if (source.Schedule != null)
                    {
                        var scheduleId = source.Schedule.Id;

                        var schedule = session.Get<Schedule>(scheduleId);
                        if (schedule == null)
                        {
                            throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(scheduleId),
                                string.Format("Расписание [{0}] не найдено", scheduleId));
                        }
                        serviceRendering.Schedule = schedule;
                    }
                    else
                    {
                        serviceRendering.Schedule = null;
                    }

                    if (source.Operator != null)
                    {
                        var operatorId = source.Operator.Id;

                        var queueOperator = session.Get<Operator>(operatorId);
                        if (queueOperator == null)
                        {
                            throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(operatorId),
                                string.Format("Оператор [{0}] не найден", operatorId));
                        }
                        serviceRendering.Operator = queueOperator;
                    }
                    else
                    {
                        serviceRendering.Operator = null;
                    }

                    if (source.ServiceStep != null)
                    {
                        var serviceStepId = source.ServiceStep.Id;

                        var serviceStep = session.Get<ServiceStep>(serviceStepId);
                        if (serviceStep == null)
                        {
                            throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(serviceStepId),
                                string.Format("Этап услуги [{0}] не найден", serviceStepId));
                        }
                        serviceRendering.ServiceStep = serviceStep;
                    }
                    else
                    {
                        serviceRendering.ServiceStep = null;
                    }

                    serviceRendering.Mode = source.Mode;
                    serviceRendering.Priority = source.Priority;

                    var errors = serviceRendering.Validate();
                    if (errors.Length > 0)
                    {
                        throw new FaultException(errors.First().Message);
                    }

                    session.Save(serviceRendering);

                    var todayQueuePlan = QueueInstance.TodayQueuePlan;
                    using (var locker = todayQueuePlan.WriteLock())
                    {
                        transaction.Commit();

                        todayQueuePlan.Flush(QueuePlanFlushMode.ServiceRenderings);
                        todayQueuePlan.Build(DateTime.Now.TimeOfDay);
                    }

                    return Mapper.Map<ServiceRendering, DTO.ServiceRendering>(serviceRendering);
                }
            });
        }