public JsonResult Enrol(TrialViewModel model)
 {
     var trial = new Trial
                     {
                         DateRequested = DateTime.UtcNow,
                         Id = IlluminateDatabase.GenerateId<Trial>(),
                         OrgName = model.OrgName,
                         OwnerName = model.OwnerName,
                         OwnerEmail = model.EmailAddress
                     };
     using (var session = MasterStore.OpenSession())
     {
         session.Store(trial);
         session.SaveChanges();
     }
     return JsonSuccess("Trial created");
 }
Example #2
0
        public static void CreateTrial()
        {
            var connectionString = ConfigurationManager.AppSettings["RavenMaster"];

            var ds = new DocumentStore();
            ds.ParseConnectionString(connectionString); //done this way to allow environment variable overwrite on appharbor for backgroundworker
            ds.Conventions = new DocumentConvention
            {
                DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites
            };

            ds.Initialize();

            using (var session = ds.OpenSession())
            {
                var trial = new Trial
                                {
                                    DateRequested = DateTime.UtcNow,
                                    Id = IlluminateDatabase.GenerateId<Trial>(),
                                    OrgName = "Amber Taxis",
                                    OwnerEmail = "*****@*****.**",
                                    OwnerName = "Andy Evans"
                                };

                session.Store(trial);
                session.SaveChanges();
            }
        }
        private bool GenerateDataForATrial(Trial trial)
        {
            var orgKey = trial.OrgName.Replace(' ', '_').ToLower() + "_" + Guid.NewGuid();
            //set up RavenDB for org store
            string reservedDatabaseId;
            var orgStore = _database.ReserveDatabase(trial.RewardPoints, trial.OrgName, orgKey,out  reservedDatabaseId);
            if (orgStore == null)
            {
                _logger.Warn(string.Format("No more banked databases left to be used."));
                return false;
            }
            var splitOwnerName = trial.OwnerName.Split(' ');
            if (string.IsNullOrEmpty(trial.OwnerName))
            {
                _logger.WarnFormat("Trial name is null or empty");
                return false;
            }

            if (splitOwnerName.Length < 2)
            {
                _logger.WarnFormat("Trial owner name is wrong format {0}",trial.OwnerName);
                return false;
            }
            try
            {
                var generator = new TrialDataGenerator(trial.OrgName, splitOwnerName[0], splitOwnerName[1],
                                                       trial.OwnerEmail, orgKey);
                var config = generator.GetProvisionerConfig();
                _logger.Info(
                    string.Format("About to generate a new trial for orgkey {0}, owner name {1}, owner email {2}",
                                  orgKey, trial.OwnerName, trial.OwnerEmail));
                var orgDataGenerator = new OrgDataGenerator(config, orgStore, _database.MasterStore, _logger)
                    .GenerateConcern()
                    //.GenerateEmails()
                    .GenerateHigs()
                    .GenerateLeave()
                    .GeneratePraise()
                    .GenerateRewards()
                    .GenerateSickness()
                    //.GenerateYammers()
                    .GenerateTasks()
                    .SetupAvatars();


                trial.IsActivated = true;
                trial.DateActivated = DateTime.UtcNow;
                var refreshUserState = new RefreshUserState();
                refreshUserState.RefreshUserStateFor(orgStore);
                using (var session = _database.GetMasterSession())
                {
                    session.Store(trial);
                    session.SaveChanges();
                }
                _logger.Info(string.Format("processed trial for {0}", orgKey));
                return true;
            }
            catch (Exception ex)
            {
                _logger.ErrorFormat("Problem generating data for a trial - exception {0}",ex);
                
                return false;
            }
        }