Esempio n. 1
0
        protected void LoadMasterStoreDefaults()
        {
            using (var session = MasterStore.OpenSession())
            {
                var leaveType = new LeaveType {Code = "annualleave", Name = "Annual Leave"};
                session.Store(leaveType);
                var sicknessReasons = new List<SicknessReason>
                                          {
                                            new SicknessReason
                                                {
                                                    Children = new List<SicknessReason>
                                                                   {
                                                                       new SicknessReason
                                                                           {
                                                                               Code = "lumbago",
                                                                               Description = "desc",
                                                                               FullName = "fullname",
                                                                               Id=IlluminateDatabase.GenerateId<SicknessReason>()
                                                                           },
                                                                   },
                                                                   Code = "back",
                                                                   Id = IlluminateDatabase.GenerateId<SicknessReason>()
                                                },
                                                new SicknessReason
                                                {
                                                    Children = new List<SicknessReason>
                                                                   {
                                                                       new SicknessReason
                                                                           {
                                                                               Code = "ankle",
                                                                               Description = "desc",
                                                                               FullName = "fullname",
                                                                               Id=IlluminateDatabase.GenerateId<SicknessReason>()
                                                                           },
                                                                   },
                                                                   Code = "joints",
                                                                   Id = IlluminateDatabase.GenerateId<SicknessReason>()
                                                }
                                          };
                var sc = new SicknessClassification
                             {
                                 SicknessReasons = sicknessReasons

                             };
                session.Store(sc);
                session.SaveChanges();
            }
        }
        public ActionResult CreateSicknessReasons(string reasons)
        {
            using (var MasterSession = MasterStore.OpenSession())
            {


                var current = MasterSession.Query<SicknessClassification>().FirstOrDefault();
                if (current == null)
                {
                    current = new SicknessClassification();
                    current.SicknessReasons = new List<SicknessReason>();
                    MasterSession.Store(current);
                    MasterSession.SaveChanges();
                }

                var allreasons = current.Flatten();

                var re = new Regex(@"^(?<code>[^\t]+)\t(?<parent>[^\t]*)\t(?<name>[^\t]+)$");
                foreach (var line in reasons.Split('\n'))
                {
                    var matches = re.Match(line);
                    if (matches.Success)
                    {
                        var code = matches.Groups["code"].Captures[0].Value.Trim();
                        var name = matches.Groups["name"].Captures[0].Value.Trim();
                        var parent = matches.Groups["parent"].Captures[0].Value.Trim();

                        //check for existing already.
                        var check = allreasons.Where(r => r.Code == code).Count();
                        if (check == 0)
                        {
                            var newtype = new SicknessReason
                                              {
                                                  Id = IlluminateDatabase.GenerateId<SicknessReason>(),
                                                  Code = code,
                                                  Name = name,
                                                  Description = name,
                                                  FullName = name,
                                                  Children = new List<SicknessReason>()
                                              };
                            //get parent. 
                            var parenttype = allreasons.Where(r => r.Code == parent).FirstOrDefault();
                            if (parenttype == null)
                            {
                                //top level. 
                                if (current.SicknessReasons == null)
                                    current.SicknessReasons = new List<SicknessReason>();
                                current.SicknessReasons.Add(newtype);
                            }
                            else
                            {
                                if (parenttype.Children == null) parenttype.Children = new List<SicknessReason>();
                                parenttype.Children.Add(newtype);
                            }
                            allreasons.Add(newtype);
                        }
                    }
                }


                MasterSession.SaveChanges();
            }

            return CreateSicknessReasons();
        }
        private OrgDataGenerator GenerateLookupData()
        {
            _logger.Info(string.Format("Data generator - about to setup lookup data"));
            using (var masterSession = _masterStore.OpenSession())
            {
                var lt = masterSession.Query<LeaveType>().FirstOrDefault();
                if (lt == null)
                {
                    throw new InvalidOperationException(string.Format("No leave types set up in master store with url {0}",_masterStore.Url));
                }
                lt.Id = IlluminateDatabase.GenerateId<LeaveType>();
                var sc = masterSession.Query<SicknessClassification>().FirstOrDefault();
                if (sc == null)
                {
                    throw new InvalidOperationException(string.Format("No sickness classifications set up in master store with url {0}", _masterStore.Url));
                }
                
                using (var orgSession = _orgStore.OpenSession())
                {
                  orgSession.Store(sc);
                  orgSession.Store(lt);
                  
                  _possibleAttributes = Attribute.GetDefaults();

                  foreach (var defaultAttribute in _possibleAttributes)
                  {
                      defaultAttribute.Id = IlluminateDatabase.GenerateId<Attribute>();
                      orgSession.Store(defaultAttribute);
                  }
                  orgSession.SaveChanges();
                }
                
                _leaveType=lt;
                _sicknessClassification = sc;
            }
            _logger.Info(string.Format("Data generator - successfully setup Avatars"));
            return this;

        }