コード例 #1
0
 public DataMigrations(ISqlConnections sqlConnections, IWebHostEnvironment hostEnvironment)
 {
     SqlConnections = sqlConnections ??
                      throw new ArgumentNullException(nameof(sqlConnections));
     HostEnvironment = hostEnvironment ??
                       throw new ArgumentNullException(nameof(hostEnvironment));
 }
コード例 #2
0
 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));
 }
コード例 #3
0
 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));
 }
コード例 #4
0
        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;
        }
コード例 #5
0
ファイル: DashboardPage.cs プロジェクト: Flave1/Inventory
        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));
        }
コード例 #6
0
 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));
 }
コード例 #7
0
 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));
 }
コード例 #8
0
 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;
 }
コード例 #9
0
        public JobLogger(
            bool logToFile,
            bool logToConsole,
            bool logToDatabase)
        {
            _logToFile = logToFile;
            _logToConsole = logToConsole;
            _logToDatabase = logToDatabase;

            this.sqlConnections = new SqlConnections();
        }
コード例 #10
0
        /// <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));
        }
コード例 #11
0
        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
                }));
            }
        }
コード例 #12
0
        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)));
                }
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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";
        }
コード例 #15
0
ファイル: CustomerCity.cs プロジェクト: olenake/Serene
 public CustomerCityLookup(ISqlConnections sqlConnections)
     : base(sqlConnections)
 {
     IdField = TextField = CustomerRow.Fields.City.PropertyName;
 }
コード例 #16
0
 public DynamicNavigationSample(ISqlConnections sqlConnections)
 {
     SqlConnections = sqlConnections ??
                      throw new ArgumentNullException(nameof(sqlConnections));
 }
コード例 #17
0
ファイル: LookUps.cs プロジェクト: gsaielli/cave-serene
 public AutorizzazioneLookup(ISqlConnections sqlConnections) : base(sqlConnections)
 {
     IdField = TextField = AutorizzazioneRow.Fields.Id.PropertyName;
 }
コード例 #18
0
 public LanguageLookup(ISqlConnections sqlConnections)
     : base(sqlConnections)
 {
     IdField    = LanguageRow.Fields.LanguageId.PropertyName;
     Permission = "*";
 }
コード例 #19
0
 public EmployeeListDecorator(ITwoLevelCache cache, ISqlConnections sqlConnections)
 {
     Cache          = cache ?? throw new ArgumentNullException(nameof(cache));
     SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections));
 }
コード例 #20
0
        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();
            }));
        }
コード例 #21
0
            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);
            }
コード例 #22
0
        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"
                });
            }
        }
コード例 #23
0
 public UserRetrieveService(ITwoLevelCache cache, ISqlConnections sqlConnections)
 {
     Cache          = cache;
     SqlConnections = sqlConnections;
 }
コード例 #24
0
 public ActionResult DragDropInTreeGrid([FromServices] ISqlConnections sqlConnections)
 {
     Repositories.DragDropSampleRepository.PopulateInitialItems(sqlConnections);
     return(View(Views.DragDropInTreeGrid.Index));
 }
コード例 #25
0
 public SupplierCountryLookup(ISqlConnections sqlConnections)
     : base(sqlConnections)
 {
     IdField = TextField = "Country";
 }
コード例 #26
0
 public CustomerLookup(ISqlConnections sqlConnections)
     : base(sqlConnections)
 {
     IdField   = CustomerRow.Fields.CustomerID.PropertyName;
     TextField = CustomerRow.Fields.CompanyName.PropertyName;
 }
コード例 #27
0
 public OrderShipCityLookup(ISqlConnections sqlConnections)
     : base(sqlConnections)
 {
     IdField = TextField = OrderRow.Fields.ShipCity.PropertyName;
 }
コード例 #28
0
ファイル: LookUps.cs プロジェクト: gsaielli/cave-serene
 public ConcessioneLookup(ISqlConnections sqlConnections) : base(sqlConnections)
 {
     IdField = TextField = ConcessioneRow.Fields.Id.PropertyName;
 }
コード例 #29
0
 public OrderDetailReport(ISqlConnections sqlConnections)
 {
     SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections));
 }
コード例 #30
0
 public NotesBehavior(IRequestContext context, ISqlConnections sqlConnections)
 {
     Context        = context ?? throw new ArgumentNullException(nameof(context));
     SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections));
 }