public void ConfigureDbContext(IServiceCollection services, string connectionString)
        {
            var customersConnectionString = connectionString.Replace("angular-my-microting-plugin", "eform-angular-basecustomer-plugin");
            var orgConnectionString       = connectionString.Replace("angular-my-microting-plugin", "angular-my-microting-organizations-plugin");

            // todo: connection string, seed customers db, same for my microting db context
            services.AddDbContext <DigitalOceanDbContext>(o => o.UseMySql(connectionString,
                                                                          b => b.MigrationsAssembly(PluginAssembly().FullName)));

            services.AddDbContext <CustomersPnDbAnySql>(o => o.UseMySql(customersConnectionString,
                                                                        b => b.MigrationsAssembly(PluginAssembly().FullName)));

            services.AddDbContext <MyMicrotingDbContext>(o => o.UseMySql(orgConnectionString,
                                                                         b => b.MigrationsAssembly(PluginAssembly().FullName)));

            DigitalOceanDbContextFactory contextFactory = new DigitalOceanDbContextFactory();

            using (DigitalOceanDbContext context = contextFactory.CreateDbContext(new[] { connectionString }))
                context.Database.Migrate();

            CustomersPnContextFactory customersPnContextFactory = new CustomersPnContextFactory();

            using (CustomersPnDbAnySql context = customersPnContextFactory.CreateDbContext(new[] { customersConnectionString }))
                context.Database.Migrate();

            MyMicrotingDbContextFactory myMicrotingDbContextFactory = new MyMicrotingDbContextFactory();

            using (MyMicrotingDbContext context = myMicrotingDbContextFactory.CreateDbContext(new[] { orgConnectionString }))
                context.Database.Migrate();

            // Seed database
            SeedDatabase(connectionString);
        }
Exemple #2
0
        public async Task Update(CustomersPnDbAnySql dbContext)
        {
            Invoice invoice = dbContext.Invoices.FirstOrDefault(x => x.Id == Id);

            if (invoice == null)
            {
                throw new NullReferenceException($"Could not find Invoice with {Id}");
            }

            invoice.CustomerId            = CustomerId;
            invoice.Currency              = Currency;
            invoice.Date                  = Date;
            invoice.DueDate               = DueDate;
            invoice.GrossAmount           = GrossAmount;
            invoice.NetAmount             = NetAmount;
            invoice.OrderId               = OrderId;
            invoice.Pdf                   = Pdf;
            invoice.VatAmount             = VatAmount;
            invoice.Remainder             = Remainder;
            invoice.RemainderBaseCurrency = RemainderBaseCurrency;
            invoice.VatIncluded           = VatIncluded;
            invoice.PageNo                = PageNo;
            invoice.ApiId                 = ApiId;

            if (dbContext.ChangeTracker.HasChanges())
            {
                invoice.UpdatedAt = DateTime.Now;
                invoice.Version  += 1;
                await dbContext.SaveChangesAsync();

                dbContext.InvoiceVersions.Add(MapVersions(invoice));
                await dbContext.SaveChangesAsync();
            }
        }
Exemple #3
0
 public FieldsService(ILogger <FieldsService> logger,
                      CustomersPnDbAnySql dbContext,
                      ICustomersLocalizationService localizationService)
 {
     _logger              = logger;
     _dbContext           = dbContext;
     _localizationService = localizationService;
 }
Exemple #4
0
 public MailService(IImportsService importsService,
                    eFormRentableItemPnDbContext dbContext,
                    CustomersPnDbAnySql customerDbContext)
 {
     _importsService    = importsService;
     _dbContext         = dbContext;
     _customerDbContext = customerDbContext;
 }
        public void SeedDatabase(string connectionString)
        {
            // Get DbContext
            CustomersPnContextFactory contextFactory = new CustomersPnContextFactory();

            using (CustomersPnDbAnySql context = contextFactory.CreateDbContext(new[] { connectionString }))
            {
                // Add data
                List <string>
                customerFields =
                    new Customer().GetPropList();                //Find all attributes for cusomers and puts them in a list
                customerFields.Remove(nameof(Customer
                                             .RelatedEntityId)); // removes the related entity, because it's not relevant for fields
                foreach (string name in customerFields)
                {
                    if (!context.Fields.Any(x => x.Name == name))
                    {
                        Field newField = new Field
                        {
                            Name = name
                        };
                        newField.Create(context);
                    }
                }

                context.SaveChanges();
                var   nameOf         = nameof(Customer.RelatedEntityId);
                Field fieldForRemove = context.Fields.FirstOrDefault(x => x.Name == nameOf);
                if (fieldForRemove != null)
                {
                    context.Fields.Remove(fieldForRemove);
                    context.SaveChanges();
                }

                List <Field> fields = context.Fields.OrderBy(x => x.Id).ToList();
                int          i      = 1;
                foreach (Field field in fields)
                {
                    CustomerField customerField = new CustomerField
                    {
                        FieldId      = field.Id,
                        FieldStatus  = 1,
                        DisplayIndex = field.Name == "Id" ? 0 : i
                    };
                    if (!context.CustomerFields.Any(x => x.FieldId == field.Id))
                    {
                        context.CustomerFields.Add(customerField);
                    }

                    i += 1;
                }

                context.SaveChanges();

                // Seed configuration
                CustomersPluginSeed.SeedData(context);
            }
        }
Exemple #6
0
        // private static string userName = "******";
        // private static string password = "******";
        // private static string databaseName = "__DBNAME__";
        // private static string databaseServerId = "__DB_SERVER_ID__";
        // private static string directoryId = "__DIRECTORY_ID__";
        // private static string applicationId = "__APPLICATION_ID__";

        //public RentableItemsPnDbAnySql db;

        public void GetContext(string connectionStr)
        {
            CustomersPnContextFactory contextFactory = new CustomersPnContextFactory();

            DbContext = contextFactory.CreateDbContext(new[] { connectionStr });

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
 public ImportsService(IEFormCoreService coreHelper,
                       CustomersPnDbAnySql customerDbContext,
                       ILogger <ContractRentableItemService> logger,
                       eFormRentableItemPnDbContext dbContext)
 {
     _coreHelper        = coreHelper;
     _customerDbContext = customerDbContext;
     _dbContext         = dbContext;
     _logger            = logger;
 }
Exemple #8
0
 public OrganizationsService(ILocalizationService localizationService, ILogger <OrganizationsService> logger,
                             DigitalOceanDbContext doDbContext, MyMicrotingDbContext myMicrotingDbContext, CustomersPnDbAnySql customersDbContext,
                             IHttpContextAccessor httpContextAccessor, IMapper mapper)
 {
     this.localizationService = localizationService;
     this.doDbContext         = doDbContext;
     this.customersDbContext  = customersDbContext;
     this.mapper = mapper;
     this.myMicrotingDbContext = myMicrotingDbContext;
     this.httpContextAccessor  = httpContextAccessor;
     this.logger = logger;
 }
        public async Task Create(CustomersPnDbAnySql dbContext)
        {
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;
            Version       = 1;
            WorkflowState = Constants.WorkflowStates.Created;

            dbContext.Customers.Add(this);
            await dbContext.SaveChangesAsync();

            dbContext.CustomerVersions.Add(MapVersions(this));
            await dbContext.SaveChangesAsync();
        }
Exemple #10
0
        private void UpdateFields(CustomersPnDbAnySql dbContext, FieldsUpdateModel fieldsUpdate, List <CustomerField> customerFields)
        {
            foreach (CustomerField field in customerFields)                                                   // Itterating through a list of customerFields.
            {
                FieldUpdateModel fieldModel = fieldsUpdate.Fields.FirstOrDefault(x => x.Id == field.FieldId); // takes field from list of fields
                if (fieldModel != null)
                {
                    field.FieldStatus = fieldModel.FieldStatus;// sets new status for field, based on the updatemodels status.
                }
            }

            dbContext.SaveChanges();
        }
 public ContractRentableItemService(eFormRentableItemPnDbContext dbContext,
                                    ILogger <ContractRentableItemService> logger,
                                    IEFormCoreService coreHelper,
                                    IRentableItemsLocalizationService rentableItemLocalizationService,
                                    CustomersPnDbAnySql customerDbContext
                                    )
 {
     _dbContext  = dbContext;
     _logger     = logger;
     _coreHelper = coreHelper;
     _rentableItemsLocalizationService = rentableItemLocalizationService;
     _customerDbContext = customerDbContext;
 }
 public CustomersService(ILogger <CustomersService> logger,
                         CustomersPnDbAnySql dbContext,
                         IEFormCoreService coreHelper,
                         ICustomersLocalizationService customersLocalizationService,
                         IUserService userService,
                         IPluginDbOptions <CustomersSettings> options)
 {
     _logger     = logger;
     _dbContext  = dbContext;
     _coreHelper = coreHelper;
     _customersLocalizationService = customersLocalizationService;
     _options     = options;
     _userService = userService;
 }
 public CustomersSettingsService(ILogger <CustomersSettingsService> logger,
                                 CustomersPnDbAnySql dbContext,
                                 IEFormCoreService coreHelper,
                                 ICustomersLocalizationService customersLocalizationService,
                                 IPluginDbOptions <CustomersSettings> options,
                                 IHttpContextAccessor httpContextAccessor)
 {
     _logger     = logger;
     _dbContext  = dbContext;
     _coreHelper = coreHelper;
     _customersLocalizationService = customersLocalizationService;
     _options             = options;
     _httpContextAccessor = httpContextAccessor;
 }
Exemple #14
0
 public InstallationsService(
     InstallationCheckingPnDbContext installationCheckingContext,
     CustomersPnDbAnySql customersContext,
     IPluginDbOptions <InstallationCheckingBaseSettings> options,
     IInstallationCheckingLocalizationService localizationService,
     IUserService userService,
     IEFormCoreService coreHelper
     )
 {
     _installationCheckingContext = installationCheckingContext;
     _customersContext            = customersContext;
     _options             = options;
     _localizationService = localizationService;
     _userService         = userService;
     _coreHelper          = coreHelper;
 }
        public async Task Update(CustomersPnDbAnySql dbContext)
        {
            Customer customer = dbContext.Customers.FirstOrDefault(x => x.Id == Id);

            if (customer == null)
            {
                throw new NullReferenceException($"Could not find Customer with {Id}");
            }

            customer.CityName              = CityName;
            customer.CompanyAddress        = CompanyAddress;
            customer.CompanyAddress2       = CompanyAddress2;
            customer.CompanyName           = CompanyName;
            customer.ContactPerson         = ContactPerson;
            customer.CustomerNo            = CustomerNo;
            customer.Description           = Description;
            customer.Email                 = Email;
            customer.Phone                 = Phone;
            customer.ZipCode               = ZipCode;
            customer.RelatedEntityId       = RelatedEntityId;
            customer.WorkflowState         = WorkflowState;
            customer.EanCode               = EanCode;
            customer.VatNumber             = VatNumber;
            customer.CreatedBy             = CreatedBy;
            customer.CreatedDate           = CreatedDate;
            customer.CountryCode           = CountryCode;
            customer.CrmId                 = CrmId;
            customer.CadastralNumber       = CadastralNumber;
            customer.PropertyNumber        = PropertyNumber;
            customer.ApartmentNumber       = ApartmentNumber;
            customer.CompletionYear        = CompletionYear;
            customer.FloorsWithLivingSpace = FloorsWithLivingSpace;
            customer.CadastralType         = CadastralType;

            if (dbContext.ChangeTracker.HasChanges())
            {
                customer.UpdatedAt = DateTime.Now;
                customer.Version  += 1;
                await dbContext.SaveChangesAsync();

                dbContext.CustomerVersions.Add(MapVersions(customer));
                await dbContext.SaveChangesAsync();
            }
        }
        public void ConfigureDbContext(IServiceCollection services, string connectionString)
        {
            services.AddDbContext <CustomersPnDbAnySql>(o => o.UseMySql(connectionString, new MariaDbServerVersion(
                                                                            new Version(10, 4, 0)), mySqlOptionsAction: builder =>
            {
                builder.EnableRetryOnFailure();
                builder.MigrationsAssembly(PluginAssembly().FullName);
            }));

            CustomersPnContextFactory contextFactory = new CustomersPnContextFactory();

            using (CustomersPnDbAnySql context = contextFactory.CreateDbContext(new[] { connectionString }))
            {
                context.Database.Migrate();
            }

            // Seed database
            SeedDatabase(connectionString);
        }
Exemple #17
0
        public static void SeedData(CustomersPnDbAnySql dbContext)
        {
            var seedData          = new CustomersConfigurationSeedData();
            var configurationList = seedData.Data;

            foreach (var configurationItem in configurationList)
            {
                if (!dbContext.PluginConfigurationValues.Any(x => x.Name == configurationItem.Name))
                {
                    var newConfigValue = new PluginConfigurationValue()
                    {
                        Name            = configurationItem.Name,
                        Value           = configurationItem.Value,
                        CreatedAt       = DateTime.UtcNow,
                        Version         = 1,
                        WorkflowState   = Constants.WorkflowStates.Created,
                        CreatedByUserId = 1
                    };
                    dbContext.PluginConfigurationValues.Add(newConfigValue);
                    dbContext.SaveChanges();
                }
            }

            // Seed plugin permissions
            var newPermissions = CustomersPermissionsSeedData.Data
                                 .Where(p => dbContext.PluginPermissions.All(x => x.ClaimName != p.ClaimName))
                                 .Select(p => new PluginPermission
            {
                PermissionName  = p.PermissionName,
                ClaimName       = p.ClaimName,
                CreatedAt       = DateTime.UtcNow,
                Version         = 1,
                WorkflowState   = Constants.WorkflowStates.Created,
                CreatedByUserId = 1
            }
                                         );

            dbContext.PluginPermissions.AddRange(newPermissions);

            dbContext.SaveChanges();
        }
Exemple #18
0
        public async Task Delete(CustomersPnDbAnySql dbContext)
        {
            Invoice invoice = dbContext.Invoices.FirstOrDefault(x => x.Id == Id);

            if (invoice == null)
            {
                throw new NullReferenceException($"Could not find Invoice with {Id}");
            }

            invoice.WorkflowState = Constants.WorkflowStates.Removed;

            if (dbContext.ChangeTracker.HasChanges())
            {
                invoice.UpdatedAt = DateTime.Now;
                invoice.Version  += 1;
                await dbContext.SaveChangesAsync();

                dbContext.InvoiceVersions.Add(MapVersions(invoice));
                await dbContext.SaveChangesAsync();
            }
        }
        public async Task Delete(CustomersPnDbAnySql dbContext)
        {
            Customer customer = dbContext.Customers.FirstOrDefault(x => x.Id == Id);

            if (customer == null)
            {
                throw new NullReferenceException($"Could not find Customer with {Id}");
            }

            customer.WorkflowState   = Constants.WorkflowStates.Removed;
            customer.RelatedEntityId = null;

            if (dbContext.ChangeTracker.HasChanges())
            {
                customer.UpdatedAt = DateTime.Now;
                customer.Version  += 1;
                await dbContext.SaveChangesAsync();

                dbContext.CustomerVersions.Add(MapVersions(customer));
                await dbContext.SaveChangesAsync();
            }
        }
        public void SeedDatabase(string connectionString)
        {
            var customersConnectionString = connectionString.Replace("angular-my-microting-plugin", "eform-angular-basecustomer-plugin");
            var orgConnectionString       = connectionString.Replace("angular-my-microting-plugin", "angular-my-microting-organizations-plugin");

            DigitalOceanDbContextFactory contextFactory = new DigitalOceanDbContextFactory();

            using (var context = contextFactory.CreateDbContext(new[] { connectionString }))
                MyMicrotingPluginSeed.SeedData(context, new MyMicrotingDropletsConfigurationSeedData());

            MyMicrotingDbContextFactory myMicrotingDbContextFactory = new MyMicrotingDbContextFactory();

            using (var context = myMicrotingDbContextFactory.CreateDbContext(new[] { orgConnectionString }))
                MyMicrotingPluginSeed.SeedData(context, new MyMicrotingOrganizationsConfigurationSeedData());

            CustomersPnContextFactory customersPnContextFactory = new CustomersPnContextFactory();

            using (CustomersPnDbAnySql context = customersPnContextFactory.CreateDbContext(new[] { customersConnectionString }))
            {
                // Add data
                List <string>
                customerFields =
                    new Customer().GetPropList();                //Find all attributes for cusomers and puts them in a list
                customerFields.Remove(nameof(Customer
                                             .RelatedEntityId)); // removes the related entity, because it's not relevant for fields
                foreach (string name in customerFields)
                {
                    if (!context.Fields.Any(x => x.Name == name))
                    {
                        Field newField = new Field
                        {
                            Name = name
                        };
                        newField.Create(context);
                    }
                }

                context.SaveChanges();
                Field fieldForRemove = context.Fields.FirstOrDefault(x => x.Name == nameof(Customer.RelatedEntityId));
                if (fieldForRemove != null)
                {
                    context.Fields.Remove(fieldForRemove);
                    context.SaveChanges();
                }

                List <Field> fields = context.Fields.ToList();
                foreach (Field field in fields)
                {
                    CustomerField customerField = new CustomerField
                    {
                        FieldId     = field.Id,
                        FieldStatus = 1
                    };
                    if (!context.CustomerFields.Any(x => x.FieldId == field.Id))
                    {
                        context.CustomerFields.Add(customerField);
                    }
                }

                context.SaveChanges();

                // Seed configuration
                MyMicrotingPluginSeed.SeedData(context, new MyMicrotingCustomersConfigurationSeedData());
                MyMicrotingPluginSeed.SeedPermissions(context, new MyMicrotingCustomersPermissionsSeedData());
            }
        }