Inheritance: IdentifiedEntity
Esempio n. 1
0
        private void demoDataMenuItem_Click(object sender, EventArgs e)
        {
            Log("Загрузка демонстрационных данных");

            using (var session = sessionProvider.OpenSession())
            using (var transaction = session.BeginTransaction())
            {
                Log("Загрузка рабочих мест");

                var w1 = session.CreateCriteria<Workplace>()
                    .Add(Restrictions.Eq("Type", WorkplaceType.Window))
                    .Add(Restrictions.Eq("Number", 1))
                    .SetMaxResults(1)
                    .UniqueResult<Workplace>();
                if (w1 == null)
                {
                    w1 = new Workplace();
                    w1.Type = WorkplaceType.Window;
                    w1.Number = 1;
                    session.Save(w1);
                }

                var w2 = session.CreateCriteria<Workplace>()
                    .Add(Restrictions.Eq("Type", WorkplaceType.Cabinet))
                    .Add(Restrictions.Eq("Number", 10))
                    .SetMaxResults(1)
                    .UniqueResult<Workplace>();
                if (w2 == null)
                {
                    w2 = new Workplace();
                    w2.Type = WorkplaceType.Cabinet;
                    w2.Number = 10;
                    session.Save(w2);
                }

                var w3 = session.CreateCriteria<Workplace>()
                    .Add(Restrictions.Eq("Type", WorkplaceType.Room))
                    .Add(Restrictions.Eq("Number", 5))
                    .SetMaxResults(1)
                    .UniqueResult<Workplace>();
                if (w3 == null)
                {
                    w3 = new Workplace();
                    w3.Type = WorkplaceType.Room;
                    w3.Number = 5;
                    session.Save(w3);
                }

                Log("Загрузка операторов");

                var o1 = session.CreateCriteria<Operator>()
                    .Add(Restrictions.Eq("Surname", "Сидоров"))
                    .SetMaxResults(1)
                    .UniqueResult<Operator>();
                if (o1 == null)
                {
                    o1 = new Operator()
                    {
                        IsActive = true,
                        Name = "Денис",
                        Surname = "Сидоров",
                        SessionId = Guid.NewGuid(),
                        Workplace = w1
                    };
                    session.Save(o1);
                }

                var o2 = session.CreateCriteria<Operator>()
                    .Add(Restrictions.Eq("Surname", "Шитиков"))
                    .SetMaxResults(1)
                    .UniqueResult<Operator>();
                if (o2 == null)
                {
                    o2 = new Operator()
                    {
                        IsActive = true,
                        Name = "Андрей",
                        Surname = "Шитиков",
                        SessionId = Guid.NewGuid(),
                        Workplace = w2
                    };
                    session.Save(o2);
                }

                var o3 = session.CreateCriteria<Operator>()
                    .Add(Restrictions.Eq("Surname", "Меньшова"))
                    .SetMaxResults(1)
                    .UniqueResult<Operator>();
                if (o3 == null)
                {
                    o3 = new Operator()
                    {
                        IsActive = true,
                        Name = "Ирина",
                        Surname = "Меньшова",
                        SessionId = Guid.NewGuid(),
                        Workplace = w3
                    };
                    session.Save(o3);
                }

                foreach (var o in new[] { o1, o2, o3 })
                {
                    foreach (var d in new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday,
                        DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday })
                    {
                        var s = session.CreateCriteria<DefaultWeekdaySchedule>()
                            .Add(Restrictions.Eq("DayOfWeek", d))
                            .UniqueResult<DefaultWeekdaySchedule>();
                        if (s != null)
                        {
                            session.Save(new ServiceRendering()
                            {
                                Mode = ServiceRenderingMode.AllRequests,
                                Operator = o,
                                Schedule = s
                            });
                        }
                    }
                }

                Log("Загрузка услуг");

                var all = ClientRequestRegistrator.Terminal
                    | ClientRequestRegistrator.Manager
                    | ClientRequestRegistrator.Portal;

                for (int i = 1; i < 10; i++)
                {
                    var code = string.Format("{0}.0", i);

                    var s = session.CreateCriteria<Service>()
                        .Add(Restrictions.Eq("Code", code))
                        .SetMaxResults(1)
                        .UniqueResult<Service>();
                    if (s == null)
                    {
                        session.Save(new Service()
                        {
                            IsActive = true,
                            Code = code,
                            Name = string.Format("Новая услуга {0}", i),
                            LiveRegistrator = all,
                            EarlyRegistrator = all,
                            TimeIntervalRounding = TimeSpan.FromMinutes(5),
                            MaxEarlyDays = 30,
                            MaxClientRecalls = 2,
                            Color = "#0000FF",
                            FontSize = 1,
                            ClientRequire = true,
                            MaxSubjects = 5,
                            SortId = i
                        });
                    }
                }

                Log("Загрузка дополнительных услуг");

                foreach (var n in new string[] { "Ксерокопия документа", "Заполнение бланка" })
                {
                    var a = session.CreateCriteria<AdditionalService>()
                        .Add(Restrictions.Eq("Name", n))
                        .SetMaxResults(1)
                        .UniqueResult<AdditionalService>();
                    if (a == null)
                    {
                        session.Save(new AdditionalService()
                        {
                            Name = n,
                            Price = 500,
                            Measure = "шт"
                        });
                    }
                }

                transaction.Commit();
            }

            Log("Загрузка демонстрационных данных завершена");
        }
Esempio n. 2
0
        public async Task<DTO.Workplace> EditWorkplace(DTO.Workplace source)
        {
            return await Task.Run(() =>
            {
                CheckPermission(UserRole.Administrator, AdministratorPermissions.Workplaces);

                using (var session = SessionProvider.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    Workplace workplace;

                    if (!source.Empty())
                    {
                        var workplaceId = source.Id;
                        workplace = session.Get<Workplace>(workplaceId);
                        if (workplace == null)
                        {
                            throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(workplaceId), string.Format("Рабочее место [{0}] не найдено", workplaceId));
                        }
                    }
                    else
                    {
                        workplace = new Workplace();
                    }

                    workplace.Type = source.Type;
                    workplace.Number = source.Number;
                    workplace.Modificator = source.Modificator;
                    workplace.Comment = source.Comment;
                    workplace.DisplayDeviceId = source.DisplayDeviceId;
                    workplace.QualityPanelDeviceId = source.QualityPanelDeviceId;

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

                    session.Save(workplace);

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

                        todayQueuePlan.Put(workplace);
                    }

                    return Mapper.Map<Workplace, DTO.Workplace>(workplace);
                }
            });
        }