예제 #1
0
        /// <summary>
        /// Reinitialisation des quota
        /// </summary>
        /// <param name="dbcontext"></param>
        /// <param name="currentDate"></param>
        public void InitializeQuota(GestecoContext dbcontext, Historique_Initialisation_Quota currentDate)
        {
            using (var transaction = dbcontext.Database.BeginTransaction())
            {
                try
                {
                    var listQuota      = dbcontext.Quota.Where(p => p.IdQuota != -1);
                    var dtdebut        = new DateTime(DateTime.Now.Year, 1, 1);
                    var dtdefin        = new DateTime(DateTime.Now.Year, 12, 31);
                    var _quotaStandard = dbcontext.Quota_Standard.First();

                    foreach (var _quota in listQuota)
                    {
                        _quota.Quantite_Commerce   = _quotaStandard.Quantite_Commerce;
                        _quota.Quantite_Disponible = _quotaStandard.Quantite;
                        _quota.DateDebut           = dtdebut;
                        _quota.DateFin             = dtdefin;
                    }


                    currentDate = dbcontext.Historique_Initialisation_Quota.FirstOrDefault(p => p.DateEncours);

                    currentDate.DateEncours = false;

                    var quotaInit = new Historique_Initialisation_Quota
                    {
                        DateEncours = true,
                        DateInit    = DateTime.Now,
                        Description = string.Format("Quota initialization started on {0}", DateTime.Now)
                    };
                    dbcontext.Historique_Initialisation_Quota.Add(quotaInit);

                    dbcontext.SaveChanges();
                    transaction.CommitAsync();
                }
                catch (Exception ex)
                {
                    transaction.RollbackAsync();
                    _logger.LogDebug("Quota initialization  Fails {0}", ex.Message);
                }
            }
        }
예제 #2
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureServices(services =>
            {
                var descriptor = services.SingleOrDefault(
                    d => d.ServiceType ==
                    typeof(DbContextOptions <GestecoContext>));

                services.Remove(descriptor);

                services.AddDbContext <GestecoContext>(options =>
                {
                    options.UseInMemoryDatabase("InMemoryDbForTesting_");
                    options.ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning));
                });

                var sp = services.BuildServiceProvider();

                using (var scope = sp.CreateScope())
                {
                    var scopedServices = scope.ServiceProvider;
                    var db             = scopedServices.GetRequiredService <GestecoContext>();
                    var logger         = scopedServices
                                         .GetRequiredService <ILogger <CustomWebApplicationFactory <TStartup> > >();

                    db.Database.EnsureCreated();

                    try
                    {
                        if (!db.Quota_Standard.Any())
                        {
                            var quota_Standard = new Quota_Standard
                            {
                                Quantite          = 20,
                                Quantite_Commerce = 20
                            };
                            db.Quota_Standard.Add(quota_Standard);
                            db.SaveChanges();
                        }

                        /// verifit s"il deja des donnee dans la table tarification
                        if (!db.Tarification.Any())
                        {
                            var tarification = new Tarification
                            {
                                Prix          = 11,
                                Prix_Commerce = 32
                            };
                            db.Tarification.Add(tarification);
                            db.SaveChanges();
                        }

                        /// verifit s"il deja des donnee dans la table ModePaiement
                        if (!db.ModePaiement.Any())
                        {
                            var modepaiement = new List <ModePaiement>
                            {
                                new  ModePaiement  {
                                    Nom = "Comptant"
                                },
                                new  ModePaiement  {
                                    Nom = "Debit"
                                },
                                new  ModePaiement  {
                                    Nom = "Credit"
                                },
                                new  ModePaiement  {
                                    Nom = "Autres"
                                },
                            };
                            db.ModePaiement.AddRange(modepaiement);
                            db.SaveChanges();
                        }

                        /// verifit s"il deja des donnee dans la table ModePaiement
                        if (!db.Historique_Initialisation_Quota.Any())
                        {
                            var quotaInit = new Historique_Initialisation_Quota
                            {
                                DateEncours = true,
                                DateInit    = DateTime.Now,
                                Description = "Initialisation de depart"
                            };

                            db.Historique_Initialisation_Quota.Add(quotaInit);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, "An error occurred seeding the " +
                                        "database with test messages. Error: {Message}", ex.Message);
                    }
                }
            });
        }
예제 #3
0
        public static void Seed(GestecoContext context)
        {
            /// verifit s"il deja des donnee dans la table quota standard
            if (!context.Quota_Standard.Any())
            {
                var quota_Standard = new Quota_Standard
                {
                    Quantite          = 20,
                    Quantite_Commerce = 20
                };
                context.Quota_Standard.Add(quota_Standard);
                context.SaveChanges();
            }

            /// verifit s"il deja des donnee dans la table tarification
            if (!context.Tarification.Any())
            {
                var tarification = new Tarification
                {
                    Prix          = 11,
                    Prix_Commerce = 32
                };
                context.Tarification.Add(tarification);
                context.SaveChanges();
            }

            /// verifit s"il deja des donnee dans la table ModePaiement
            if (!context.ModePaiement.Any())
            {
                var modepaiement = new List <ModePaiement>
                {
                    new  ModePaiement  {
                        Nom = "Comptant"
                    },
                    new  ModePaiement  {
                        Nom = "Debit"
                    },
                    new  ModePaiement  {
                        Nom = "Credit"
                    },
                    new  ModePaiement  {
                        Nom = "Autres"
                    },
                };
                context.ModePaiement.AddRange(modepaiement);
                context.SaveChanges();
            }

            /// verifit s"il deja des donnee dans la table ModePaiement
            if (!context.Historique_Initialisation_Quota.Any())
            {
                var quotaInit = new Historique_Initialisation_Quota
                {
                    DateEncours = true,
                    DateInit    = DateTime.Now,
                    Description = "Initialisation de depart"
                };

                context.Historique_Initialisation_Quota.Add(quotaInit);
                context.SaveChanges();
            }
        }