Ejemplo n.º 1
0
 public IEnumerable <Role> GetRoles()
 {
     using (var context = new SignUpContext())
     {
         return(context.Roles.ToList());
     }
 }
Ejemplo n.º 2
0
 public IEnumerable <Country> GetCountries()
 {
     using (var context = new SignUpContext())
     {
         return(context.Countries.ToList());
     }
 }
Ejemplo n.º 3
0
 public IEnumerable <User> Get()
 {
     using (var context = new SignUpContext())
     {
         return(context.Users.ToList());
     }
 }
Ejemplo n.º 4
0
        private static void SaveProspect(Prospect prospect)
        {
            using (var context = new SignUpContext())
            {
                //reload child objects:
                prospect.Country = context.Countries.Single(x => x.CountryCode == prospect.Country.CountryCode);
                prospect.Role    = context.Roles.Single(x => x.RoleCode == prospect.Role.RoleCode);

                context.Prospects.Add(prospect);
                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
 public IHttpActionResult Get(string userName, string password)
 {
     using (var context = new SignUpContext())
     {
         var user = context.Users.FirstOrDefault(x => x.UserName == userName && x.Password == password);
         if (user == null)
         {
             return(NotFound());
         }
         return(Ok(user));
     }
 }
Ejemplo n.º 6
0
        public IDictionary <string, Country> GetCountriesx()
        {
            var countries = new Dictionary <string, Country>();

            using (var context = new SignUpContext())
            {
                countries["-"] = context.Countries.Single(x => x.CountryCode == "-");
                foreach (var country in context.Countries.Where(x => x.CountryCode != "-").OrderBy(x => x.CountryName))
                {
                    countries[country.CountryCode] = country;
                }
            }
            return(countries);
        }
Ejemplo n.º 7
0
        public IDictionary <string, Role> GetRolesx()
        {
            var roles = new Dictionary <string, Role>();

            using (var context = new SignUpContext())
            {
                roles["-"] = context.Roles.Single(x => x.RoleCode == "-");
                foreach (var role in context.Roles.Where(x => x.RoleCode != "-").OrderBy(x => x.RoleName))
                {
                    roles[role.RoleCode] = role;
                }
            }
            return(roles);
        }
Ejemplo n.º 8
0
        public async Task <IHttpActionResult> PostAuthor(User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var context = new SignUpContext())
            {
                context.Users.Add(user);
                await context.SaveChangesAsync();
            }

            return(CreatedAtRoute("DefaultApi", new { userName = user.UserName }, user));
        }
Ejemplo n.º 9
0
        private void SaveProspect(Prospect prospect)
        {
            Log.Info("Saving new prospect, email address: {0}", prospect.EmailAddress);
            var stopwatch = Stopwatch.StartNew();

            using (var context = new SignUpContext())
            {
                //reload child objects:
                prospect.Country = context.Countries.Single(x => x.CountryCode == prospect.Country.CountryCode);
                prospect.Role    = context.Roles.Single(x => x.RoleCode == prospect.Role.RoleCode);

                context.Prospects.Add(prospect);
                context.SaveChanges();
            }

            Log.Info("Prospect saved, email address: {0}, ID: {1}, took: {2}ms", prospect.EmailAddress, prospect.ProspectId, stopwatch.ElapsedMilliseconds);
        }
Ejemplo n.º 10
0
 public IHttpActionResult Get()
 {
     _Logger.Debug("Fetch all users started");
     try
     {
         using (var context = new SignUpContext())
         {
             var users = context.Users.ToList();
             _Logger.Debug("Fetch all users completed");
             return(Ok(users));
         }
     }
     catch (Exception ex)
     {
         _Logger.Error(ex, "Fetch all users failed");
         return(InternalServerError(ex));
     }
 }
Ejemplo n.º 11
0
        public static void PreloadStaticDataCache()
        {
            _Countries = new Dictionary <string, Country>();
            _Roles     = new Dictionary <string, Role>();
            using (var context = new SignUpContext())
            {
                _Countries["-"] = context.Countries.Single(x => x.CountryCode == "-");
                foreach (var country in context.Countries.Where(x => x.CountryCode != "-").OrderBy(x => x.CountryName))
                {
                    _Countries[country.CountryCode] = country;
                }

                _Roles["-"] = context.Roles.Single(x => x.RoleCode == "-");
                foreach (var role in context.Roles.Where(x => x.RoleCode != "-").OrderBy(x => x.RoleName))
                {
                    _Roles[role.RoleCode] = role;
                }
            }
        }
Ejemplo n.º 12
0
 private static void EnsureDatabaseCreated()
 {
     Log.Info("Ensuring database exists");
     try
     {
         var connectionString = Config.Current.GetConnectionString("SignUpDb").ToLower();
         var server           = connectionString.Split(';').First(x => x.StartsWith("server=")).Split('=')[1];
         Log.Debug($"Connecting to database server: {server}");
         using (var context = new SignUpContext())
         {
             context.Countries.ToListAsync().Wait();
         }
         Log.Info("Database connection is OK");
     }
     catch (Exception ex)
     {
         Log.Fatal($"Database connection failed, exception: {ex}");
     }
 }
Ejemplo n.º 13
0
        private static void SaveProspect(object sender, MsgHandlerEventArgs e)
        {
            Console.WriteLine($"Received message, subject: {e.Message.Subject}");
            var eventMessage = MessageHelper.FromData <ProspectSignedUpEvent>(e.Message.Data);

            Console.WriteLine($"Saving new prospect, signed up at: {eventMessage.SignedUpAt}; event ID: {eventMessage.CorrelationId}");

            var prospect = eventMessage.Prospect;

            using (var context = new SignUpContext())
            {
                //reload child objects:
                prospect.Country = context.Countries.Single(x => x.CountryCode == prospect.Country.CountryCode);
                prospect.Role    = context.Roles.Single(x => x.RoleCode == prospect.Role.RoleCode);

                context.Prospects.Add(prospect);
                context.SaveChanges();
            }

            Console.WriteLine($"Prospect saved. Prospect ID: {eventMessage.Prospect.ProspectId}; event ID: {eventMessage.CorrelationId}");
        }
Ejemplo n.º 14
0
 public IHttpActionResult Get(string userName, string password)
 {
     _Logger.Debug("Fetch user by username started: {0}", userName);
     try
     {
         using (var context = new SignUpContext())
         {
             var user = context.Users.FirstOrDefault(x => x.UserName == userName && x.Password == password);
             if (user == null)
             {
                 _Logger.Info("Fetch user by username not found: {0}", userName);
                 return(NotFound());
             }
             _Logger.Debug("Fetch user by username completed: {0}", userName);
             return(Ok(user));
         }
     }
     catch (Exception ex)
     {
         _Logger.Error(ex, "Fetch user by username failed: {0}", userName);
         return(InternalServerError(ex));
     }
 }
Ejemplo n.º 15
0
        public async Task <IHttpActionResult> PostUser(User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _Logger.Debug("Create user started: {0}", user.UserName);
            try
            {
                using (var context = new SignUpContext())
                {
                    context.Users.Add(user);
                    await context.SaveChangesAsync();
                }
                _Logger.Debug("Create user completed: {0}", user.UserName);
                return(CreatedAtRoute("DefaultApi", new { userName = user.UserName }, user));
            }
            catch (Exception ex)
            {
                _Logger.Error(ex, "Create user failed: {0}", user.UserName);
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 16
0
        private IEnumerable <DiagnosticCheckResult> GetDbCheckResults()
        {
            var result = new DiagnosticCheckResult
            {
                CheckName = "Database connection"
            };

            try
            {
                using (var db = new SignUpContext())
                {
                    var dummy = db.Users.FirstOrDefault(x => x.Id == -1);
                    result.Passed = true;
                }
            }
            catch (Exception ex)
            {
                result.Passed = false;
                result.Notes  = $"Ex: {ex}";
            }
            return(new List <DiagnosticCheckResult> {
                result
            });
        }
Ejemplo n.º 17
0
        public static void PreloadStaticDataCache()
        {
            Log.Info("Starting pre-load data cache");
            var stopwatch = Stopwatch.StartNew();

            _Countries = new Dictionary <string, Country>();
            _Roles     = new Dictionary <string, Role>();
            using (var context = new SignUpContext())
            {
                _Countries["-"] = context.Countries.Single(x => x.CountryCode == "-");
                foreach (var country in context.Countries.Where(x => x.CountryCode != "-").OrderBy(x => x.CountryName))
                {
                    _Countries[country.CountryCode] = country;
                }

                _Roles["-"] = context.Roles.Single(x => x.RoleCode == "-");
                foreach (var role in context.Roles.Where(x => x.RoleCode != "-").OrderBy(x => x.RoleName))
                {
                    _Roles[role.RoleCode] = role;
                }
            }

            Log.Info("Completed pre-load data cache, took: {0}ms", stopwatch.ElapsedMilliseconds);
        }
Ejemplo n.º 18
0
 public QueueWorker(IConfiguration config, SignUpContext context)
 {
     _config  = config;
     _context = context;
 }
Ejemplo n.º 19
0
 //set context and logger
 public HomeController(ILogger <HomeController> logger, SignUpContext context)
 {
     _logger  = logger;
     _context = context;
 }
Ejemplo n.º 20
0
 public CheckWorker(SignUpContext context)
 {
     _context = context;
 }
Ejemplo n.º 21
0
 public SignUpRepository(SignUpContext context)
 {
     _context = context;
 }
 public SignupController(SignUpContext context)
 {
     _context = context;
 }