public DataMigrations(ISqlConnections sqlConnections, IWebHostEnvironment hostEnvironment) { SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); HostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment)); }
public NotesBehavior(IRequestContext context, ISqlConnections sqlConnections, IUserRetrieveService userRetriever) { Context = context ?? throw new ArgumentNullException(nameof(context)); SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); UserRetriever = userRetriever ?? throw new ArgumentNullException(nameof(userRetriever)); }
public CustomerGrossSalesReport(ISqlConnections sqlConnections, ITextLocalizer localizer, IServiceProvider serviceProvider) { SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); Localizer = localizer ?? throw new ArgumentNullException(nameof(localizer)); ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); }
public RowLookupScript(ISqlConnections connections) : base() { this.connections = connections ?? throw new ArgumentNullException(nameof(connections)); var row = new TRow(); if (row.IdField is object) { IdField = row.IdField.PropertyName ?? row.IdField.Name; } if (row.NameField is Field nameField) { TextField = nameField.PropertyName ?? nameField.Name; } if (row is IParentIdRow treeRow) { ParentIdField = treeRow.ParentIdField.PropertyName ?? treeRow.ParentIdField.Name; } var readPermission = typeof(TRow).GetCustomAttribute <ReadPermissionAttribute>(true); if (readPermission != null) { Permission = readPermission.Permission ?? "?"; } GroupKey = row.GetFields().GenerationKey; }
public ActionResult Index( [FromServices] ITwoLevelCache cache, [FromServices] ISqlConnections sqlConnections ) { if (cache is null) { throw new ArgumentNullException(nameof(cache)); } if (sqlConnections is null) { throw new ArgumentNullException(nameof(sqlConnections)); } var cachedModel = cache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5), OrderRow.Fields.GenerationKey, () => { var model = new DashboardPageModel(); var o = OrderRow.Fields; using (var connection = sqlConnections.NewFor <OrderRow>()) { model.OpenOrders = connection.Count <OrderRow>(o.ShippingState == (int)OrderShippingState.NotShipped); var closedOrders = connection.Count <OrderRow>(o.ShippingState == (int)OrderShippingState.Shipped); var totalOrders = model.OpenOrders + closedOrders; model.ClosedOrderPercent = (int)Math.Round(totalOrders == 0 ? 100 : ((double)closedOrders / (double)totalOrders * 100)); model.CustomerCount = connection.Count <CustomerRow>(); model.ProductCount = connection.Count <ProductRow>(); } return(model); }); return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel)); }
public EmailSender(IWebHostEnvironment host, IOptions <SmtpSettings> smtp, ISqlConnections connections, IUserAccessor userAccessor) { this.host = (host ?? throw new ArgumentNullException(nameof(host))); this.smtp = (smtp ?? throw new ArgumentNullException(nameof(smtp))).Value; this.connections = connections ?? throw new ArgumentNullException(nameof(connections)); this.userAccessor = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor)); }
public PermissionService(ITwoLevelCache cache, ISqlConnections sqlConnections, ITypeSource typeSource, IUserAccessor userAccessor) { Cache = cache ?? throw new ArgumentNullException(nameof(cache)); SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); TypeSource = typeSource ?? throw new ArgumentNullException(nameof(typeSource)); UserAccessor = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor)); }
public UserPasswordValidator(ITwoLevelCache cache, ISqlConnections sqlConnections, IUserRetrieveService userRetriever, ILogger <UserPasswordValidator> log = null, IDirectoryService directoryService = null) { Cache = cache ?? throw new ArgumentNullException(nameof(cache)); SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); UserRetriever = userRetriever ?? throw new ArgumentNullException(nameof(userRetriever)); DirectoryService = directoryService; Log = log; }
public JobLogger( bool logToFile, bool logToConsole, bool logToDatabase) { _logToFile = logToFile; _logToConsole = logToConsole; _logToDatabase = logToDatabase; this.sqlConnections = new SqlConnections(); }
/// <summary> /// Creates a new connection for specified class, determining /// the connection key by checking its [ConnectionKey] attribute. /// </summary> /// <typeparam name="TClass">The type of the class.</typeparam> /// <param name="factory">Connection factory</param> /// <returns>A new connection</returns> /// <exception cref="ArgumentOutOfRangeException">Type has no ConnectionKey attribute!</exception> public static IDbConnection NewFor <TClass>(this ISqlConnections factory) { var attr = typeof(TClass).GetCustomAttribute <ConnectionKeyAttribute>(); if (attr == null) { throw new ArgumentOutOfRangeException("Type has no ConnectionKey attribute!", typeof(TClass).FullName); } return(factory.NewByKey(attr.Value)); }
public ActionResult ResetPassword(string t, [FromServices] ISqlConnections sqlConnections) { int userId; try { var bytes = HttpContext.RequestServices .GetDataProtector("ResetPassword").Unprotect(Convert.FromBase64String(t)); using (var ms = new MemoryStream(bytes)) using (var br = new BinaryReader(ms)) { var dt = DateTime.FromBinary(br.ReadInt64()); if (dt < DateTime.UtcNow) { return(Error(Texts.Validation.InvalidResetToken.ToString(Localizer))); } userId = br.ReadInt32(); } } catch (Exception) { return(Error(Texts.Validation.InvalidResetToken.ToString(Localizer))); } if (sqlConnections is null) { throw new ArgumentNullException(nameof(sqlConnections)); } using (var connection = sqlConnections.NewFor <UserRow>()) { var user = connection.TryById <UserRow>(userId); if (user == null) { return(Error(Texts.Validation.InvalidResetToken.ToString(Localizer))); } } if (UseAdminLTELoginBox) { return(View(MVC.Views.Membership.Account.ResetPassword.AccountResetPassword_AdminLTE, new ResetPasswordModel { Token = t })); } else { return(View(MVC.Views.Membership.Account.ResetPassword.AccountResetPassword, new ResetPasswordModel { Token = t })); } }
public ActionResult Activate(string t, [FromServices] ISqlConnections sqlConnections) { using (var connection = sqlConnections.NewByKey("Default")) using (var uow = new UnitOfWork(connection)) { int userId; try { var bytes = HttpContext.RequestServices .GetDataProtector("Activate").Unprotect(Convert.FromBase64String(t)); using (var ms = new MemoryStream(bytes)) using (var br = new BinaryReader(ms)) { var dt = DateTime.FromBinary(br.ReadInt64()); if (dt < DateTime.UtcNow) { return(Error(Texts.Validation.InvalidActivateToken.ToString(Localizer))); } userId = br.ReadInt32(); } } catch (Exception) { return(Error(Texts.Validation.InvalidActivateToken.ToString(Localizer))); } var user = uow.Connection.TryById <UserRow>(userId); if (user == null || user.IsActive != 0) { return(Error(Texts.Validation.InvalidActivateToken.ToString(Localizer))); } uow.Connection.UpdateById(new UserRow { UserId = user.UserId.Value, IsActive = 1 }); Cache.InvalidateOnCommit(uow, UserRow.Fields); uow.Commit(); return(new RedirectResult("~/Account/Login?activated=" + Uri.EscapeDataString(user.Email))); } }
public ActionResult Index( [FromServices] ITwoLevelCache cache, [FromServices] ISqlConnections sqlConnections ) { if (cache is null) { throw new ArgumentNullException(nameof(cache)); } if (sqlConnections is null) { throw new ArgumentNullException(nameof(sqlConnections)); } var cachedModel = new DashboardPageModel() { }; return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel)); }
public DistinctValuesScript(ISqlConnections connections, string propertyName) { this.connections = connections ?? throw new ArgumentNullException(nameof(connections)); this.propertyName = propertyName ?? throw new ArgumentNullException(nameof(propertyName)); var row = new TRow(); var field = GetFieldFrom(row); var readPermission = field.GetAttribute <ReadPermissionAttribute>() ?? typeof(TRow).GetCustomAttribute <ReadPermissionAttribute>(true); if (readPermission != null) { Permission = readPermission.Permission ?? "?"; } GroupKey = row.GetFields().GenerationKey; TextField = "v"; IdField = "v"; }
public CustomerCityLookup(ISqlConnections sqlConnections) : base(sqlConnections) { IdField = TextField = CustomerRow.Fields.City.PropertyName; }
public DynamicNavigationSample(ISqlConnections sqlConnections) { SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); }
public AutorizzazioneLookup(ISqlConnections sqlConnections) : base(sqlConnections) { IdField = TextField = AutorizzazioneRow.Fields.Id.PropertyName; }
public LanguageLookup(ISqlConnections sqlConnections) : base(sqlConnections) { IdField = LanguageRow.Fields.LanguageId.PropertyName; Permission = "*"; }
public EmployeeListDecorator(ITwoLevelCache cache, ISqlConnections sqlConnections) { Cache = cache ?? throw new ArgumentNullException(nameof(cache)); SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); }
public Result <ServiceResponse> ResetPassword(ResetPasswordRequest request, [FromServices] ISqlConnections sqlConnections) { return(this.InTransaction("Default", uow => { if (request is null) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrEmpty(request.Token)) { throw new ArgumentNullException("token"); } var bytes = HttpContext.RequestServices .GetDataProtector("ResetPassword").Unprotect(Convert.FromBase64String(request.Token)); int userId; using (var ms = new MemoryStream(bytes)) using (var br = new BinaryReader(ms)) { var dt = DateTime.FromBinary(br.ReadInt64()); if (dt < DateTime.UtcNow) { throw new ValidationError(Texts.Validation.InvalidResetToken.ToString(Localizer)); } userId = br.ReadInt32(); } UserRow user; if (sqlConnections is null) { throw new ArgumentNullException(nameof(sqlConnections)); } using (var connection = sqlConnections.NewFor <UserRow>()) { user = connection.TryById <UserRow>(userId); if (user == null) { throw new ValidationError(Texts.Validation.InvalidResetToken.ToString(Localizer)); } } if (request.ConfirmPassword != request.NewPassword) { throw new ValidationError("PasswordConfirmMismatch", Localizer.Get("Validation.PasswordConfirm")); } request.NewPassword = UserRepository.ValidatePassword(request.NewPassword, Localizer); string salt = null; var hash = UserRepository.GenerateHash(request.NewPassword, ref salt); UserRepository.CheckPublicDemo(user.UserId); uow.Connection.UpdateById(new UserRow { UserId = user.UserId.Value, PasswordSalt = salt, PasswordHash = hash }); Cache.InvalidateOnCommit(uow, UserRow.Fields); return new ServiceResponse(); })); }
private (IEnumerable <TableName> selectedTables, List <TableName> tableNames) SelectedTables(ISqlConnections sqlConnections, string connectionKey) { ISchemaProvider schemaProvider; List <TableName> tableNames; using (var connection = sqlConnections.NewByKey(connectionKey)) { schemaProvider = SchemaHelper.GetSchemaProvider(connection.GetDialect().ServerType); tableNames = schemaProvider.GetTableNames(connection).ToList(); } var tables = tableNames.Select(x => x.Tablename).ToList(); var selectedTableNames = AnsiConsole.Prompt( new MultiSelectionPrompt <string>() .Title("[steelblue1]Select tables for code generation (single/multiple)[/]") .PageSize(10) .MoreChoicesText("[grey](Move up and down to reveal more tables)[/]") .InstructionsText( "[grey](Press [blue]<space>[/] to select/unselect, " + "[green]<enter>[/] to accept)[/]") .AddChoices(tables)); var selectedTables = tableNames.Where(s => selectedTableNames.Contains(s.Tablename)); return(selectedTables, tableNames); }
public static void PopulateInitialItems(ISqlConnections sqlConnections) { if (sqlConnections is null) { throw new ArgumentNullException(nameof(sqlConnections)); } using (var connection = sqlConnections.NewFor <MyRow>()) { if (connection.Count <MyRow>() != 0) { return; } var folder1 = (int)connection.InsertAndGetID(new MyRow { Title = "Folder 1" }); connection.Insert(new MyRow { Title = "Item 1", ParentId = folder1 }); var sub1 = (int)connection.InsertAndGetID(new MyRow { Title = "Sub folder 1", ParentId = folder1 }); connection.Insert(new MyRow { Title = "Item 2", ParentId = sub1 }); connection.Insert(new MyRow { Title = "Item 3", ParentId = sub1 }); var sub2 = (int)connection.InsertAndGetID(new MyRow { Title = "Sub folder 2", ParentId = folder1 }); connection.Insert(new MyRow { Title = "Item 4", ParentId = sub2 }); connection.Insert(new MyRow { Title = "Item 5", ParentId = sub2 }); var subsub = (int)connection.InsertAndGetID(new MyRow { Title = "Sub sub folder", ParentId = sub2 }); connection.Insert(new MyRow { Title = "Item 6", ParentId = subsub }); connection.Insert(new MyRow { Title = "Item 7", ParentId = subsub }); var folder2 = (int)connection.InsertAndGetID(new MyRow { Title = "Folder 2" }); connection.Insert(new MyRow { Title = "Item 8", ParentId = folder2 }); connection.Insert(new MyRow { Title = "Item 9" }); connection.Insert(new MyRow { Title = "Item 10" }); } }
public UserRetrieveService(ITwoLevelCache cache, ISqlConnections sqlConnections) { Cache = cache; SqlConnections = sqlConnections; }
public ActionResult DragDropInTreeGrid([FromServices] ISqlConnections sqlConnections) { Repositories.DragDropSampleRepository.PopulateInitialItems(sqlConnections); return(View(Views.DragDropInTreeGrid.Index)); }
public SupplierCountryLookup(ISqlConnections sqlConnections) : base(sqlConnections) { IdField = TextField = "Country"; }
public CustomerLookup(ISqlConnections sqlConnections) : base(sqlConnections) { IdField = CustomerRow.Fields.CustomerID.PropertyName; TextField = CustomerRow.Fields.CompanyName.PropertyName; }
public OrderShipCityLookup(ISqlConnections sqlConnections) : base(sqlConnections) { IdField = TextField = OrderRow.Fields.ShipCity.PropertyName; }
public ConcessioneLookup(ISqlConnections sqlConnections) : base(sqlConnections) { IdField = TextField = ConcessioneRow.Fields.Id.PropertyName; }
public OrderDetailReport(ISqlConnections sqlConnections) { SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); }
public NotesBehavior(IRequestContext context, ISqlConnections sqlConnections) { Context = context ?? throw new ArgumentNullException(nameof(context)); SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections)); }