Пример #1
0
        /// <summary>
        /// Connection the job to the database and execute the job
        /// </summary>
        /// <param name="verbose"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public override int Run(bool verbose = false, string[] args = null)
        {
            // Check database connection

            int status = base.Run(verbose, args);

            if (status != 0)
            {
                return(status);
            }

            // Administration Database connection

            using (Syncytium.Module.Administration.DatabaseContext adminDatabase = new Syncytium.Module.Administration.DatabaseContext())
            {
                // Open a connection to the database

                adminDatabase.Database.Connection.Open();

                // Build the database schema

                string area = Syncytium.Module.Administration.DatabaseContext.AREA_NAME;
                if (!ConfigurationManager.Schemas.ContainsKey(area))
                {
                    ConfigurationManager.Schemas[area] = new Common.Database.DSSchema.DSDatabase(typeof(Syncytium.Module.Administration.DatabaseContext), null);
                    Common.Logger.LoggerManager.Instance.Info(Common.Logger.LoggerManager.MODULE_NAME, $"Database schema[{area}] : '{ConfigurationManager.Schemas[area].ToString()}'");
                }

                // Executing the job

                try
                {
                    Execute(verbose, area, ConfigurationManager.Schemas[area], adminDatabase, args);
                }
                catch (Exception ex)
                {
                    Exception("Unable to execute the job", ex);
                    return(-1);
                }
            }

            // Stock Database connection

            using (Syncytium.Module.Customer.DatabaseContext sampleDatabase = new Syncytium.Module.Customer.DatabaseContext())
            {
                // Open a connection to the database

                sampleDatabase.Database.Connection.Open();

                // Build the database schema

                string area = Syncytium.Module.Customer.DatabaseContext.AREA_NAME;
                if (!ConfigurationManager.Schemas.ContainsKey(area))
                {
                    ConfigurationManager.Schemas[area] = new Common.Database.DSSchema.DSDatabase(typeof(Syncytium.Module.Customer.DatabaseContext), null);
                    Common.Logger.LoggerManager.Instance.Info(Common.Logger.LoggerManager.MODULE_NAME, $"Database schema[{area}] : '{ConfigurationManager.Schemas[area].ToString()}'");
                }

                // Executing the job

                try
                {
                    Execute(verbose, area, ConfigurationManager.Schemas[area], sampleDatabase, args);
                }
                catch (Exception ex)
                {
                    Exception("Unable to execute the job", ex);
                    return(-1);
                }
            }

            return(0);
        }
Пример #2
0
        public ActionResult Delete(int id, string name, string login, string email, string address, string comment)
        {
            Debug($"Get ~/Administration/Customer/Delete(id={id}, name={name}, login={login}, email={email}, address={address}, comment={comment})");

            // Only for administrator from the first customer (Syncytium)

            if (!(_userManager.GetById(int.Parse(HttpContext.User.Identity.Name)) is UserRecord user) || user.CustomerId != 1)
            {
                return(HttpNotFound());
            }

            // The customer has to exist

            CustomerRecord customer = _userManager.Database.Customer.Find(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }

            // Delete the customer in all tables having DSRecordWithCustomerId into the Database context

            Info($"Deleting the customer ({customer}) within ('{name}', '{login}', '{email}', '{address}', '{comment}') ...");

            // Each table is described by a DbSet<> object

            using (Syncytium.Module.Customer.DatabaseContext database = new Syncytium.Module.Customer.DatabaseContext())
            {
                int nbLines = 0;

                // Données référentielles

                nbLines = database.Parameter.Where(r => r.CustomerId == id).Count();
                database.Parameter.RemoveRange(database.Parameter.Where(r => r.CustomerId == id));
                database.SaveChanges();
                Info($"{nbLines} records deleted into 'Parameter'");
            }

            using (Syncytium.Module.Administration.DatabaseContext database = new Syncytium.Module.Administration.DatabaseContext())
            {
                int nbLines = 0;

                // Administration

                nbLines = database.UserModule.Where(r => r.CustomerId == id).Count();
                database.UserModule.RemoveRange(database.UserModule.Where(r => r.CustomerId == id));
                database.SaveChanges();
                Info($"{nbLines} records deleted into 'UserModule'");

                nbLines = database.Module.Where(r => r.CustomerId == id).Count();
                database.Module.RemoveRange(database.Module.Where(r => r.CustomerId == id));
                database.SaveChanges();
                Info($"{nbLines} records deleted into 'Module'");

                database.Notification.RemoveRange(database.Notification.Where(r => r.CustomerId == id));
                database.SaveChanges();
                Info($"{nbLines} records deleted into 'Notification'");

                nbLines = database.User.Where(r => r.CustomerId == id).Count();
                database.User.RemoveRange(database.User.Where(r => r.CustomerId == id));
                database.SaveChanges();
                Info($"{nbLines} records deleted into 'User'");

                nbLines = database.Language.Where(r => r.CustomerId == id).Count();
                database.Language.RemoveRange(database.Language.Where(r => r.CustomerId == id));
                database.SaveChanges();
                Info($"{nbLines} records deleted into 'Language'");

                nbLines = database._Information.Where(r => r.CustomerId == id).Count();
                database._Information.RemoveRange(database._Information.Where(r => r.CustomerId == id));
                database.SaveChanges();
                Info($"{nbLines} records deleted into '_Information'");
            }

            _userManager.Database.Customer.RemoveRange(_userManager.Database.Customer.Where(c => c.Id == id));
            _userManager.Database.SaveChanges();

            Info($"Customer deleted ...");

            return(RedirectToAction("Index"));
        }