public IEnumerable <Role> GetRoles() { using (var context = new SignUpContext()) { return(context.Roles.ToList()); } }
public IEnumerable <Country> GetCountries() { using (var context = new SignUpContext()) { return(context.Countries.ToList()); } }
public IEnumerable <User> Get() { using (var context = new SignUpContext()) { return(context.Users.ToList()); } }
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(); } }
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)); } }
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); }
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); }
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)); }
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); }
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)); } }
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; } } }
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}"); } }
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}"); }
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)); } }
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)); } }
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 }); }
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); }
public QueueWorker(IConfiguration config, SignUpContext context) { _config = config; _context = context; }
//set context and logger public HomeController(ILogger <HomeController> logger, SignUpContext context) { _logger = logger; _context = context; }
public CheckWorker(SignUpContext context) { _context = context; }
public SignUpRepository(SignUpContext context) { _context = context; }
public SignupController(SignUpContext context) { _context = context; }