Ejemplo n.º 1
0
        public void Handle(LanguageCreated createdEvent)
        {
            var repository = _container.Resolve <IReportRepository>();
            var record     = repository.LanguageRecords.SingleOrDefault(r => r.Code == createdEvent.Code);

            if (record != null)
            {
                return; //it may be the case that language record was already created by other report
            }
            record = new LanguageRecord
            {
                Id         = Guid.NewGuid(),
                Code       = createdEvent.Code,
                Name       = createdEvent.Name,
                NativeName = createdEvent.NativeName,
                Status     = createdEvent.Status.ToString(),
                Created    = createdEvent.EventCreated,
                CreatedBy  = createdEvent.EventCreatedBy
            };
            if (createdEvent.Status == CultureStatus.Active)
            {
                record.Activated   = createdEvent.EventCreated;
                record.ActivatedBy = createdEvent.EventCreatedBy;
            }
            repository.LanguageRecords.Add(record);
            repository.SaveChanges();
        }
Ejemplo n.º 2
0
        public void FilterRecordTest()
        {
            DSDatabase schema = new DSDatabase(typeof(ContextTest), null);

            LanguageRecord language = new LanguageRecord();

            dynamic value = schema.FilterRecord(language, Syncytium.Module.Administration.DatabaseContext.AREA_NAME, -1, UserProfile.EUserProfile.Administrator);
        }
Ejemplo n.º 3
0
        public void CheckPropertiesTest()
        {
            DSDatabase schema = new DSDatabase(typeof(ContextTest), null);

            LanguageRecord language = new LanguageRecord();

            // Errors errors = schema.CheckProperties(language);
        }
Ejemplo n.º 4
0
        private void UpdateAssignedInBrand(IReportRepository repository,
                                           IEnumerable <string> languages, string licenseeName, string brandName)
        {
            var brandLanguages  = languages.ToList();
            var languageRecords = repository.LanguageRecords
                                  .Where(lr => brandLanguages.Contains(lr.Code) && lr.Licensee == licenseeName)
                                  .GroupBy(lr => lr.Code)
                                  .Select(lrr => lrr.OrderBy(lr => lr.Brand == null || lr.Brand == brandName ? 0 : 1).FirstOrDefault())
                                  .ToList();

            if (languageRecords.Count() != brandLanguages.Count())
            {
                //todo: create more detailed message
                throw new RegoException(LanguageRecordsCountIsIncorrectMessage);
            }

            // add new
            languageRecords.Where(lr => lr.Brand != brandName).ForEach(record =>
            {
                if (record.Brand == null)
                {
                    record.Brand = brandName;
                    return;
                }
                var newRecord = new LanguageRecord
                {
                    Id       = Guid.NewGuid(),
                    Licensee = licenseeName,
                    Brand    = brandName
                };
                var detailFields = new[] { "Licensee", "Brand" };
                typeof(LanguageRecord).GetProperties()
                .Where(pi => pi.Name != "Id" && !detailFields.Contains(pi.Name))
                .ForEach(pi => pi.SetValue(newRecord, pi.GetValue(record)));
                repository.LanguageRecords.Add(newRecord);
            });

            // remove old
            repository.LanguageRecords
            .Where(lr => !brandLanguages.Contains(lr.Code) && lr.Licensee == licenseeName && lr.Brand == brandName)
            .ToList()
            .ForEach(record =>
            {
                if (repository.LanguageRecords.Any(lr => lr.Code == record.Code && lr.Licensee == licenseeName && lr.Id != record.Id))
                {
                    repository.LanguageRecords.Remove(record);
                }
                else
                {
                    record.Brand = null;
                }
            });

            repository.SaveChanges();
        }
Ejemplo n.º 5
0
 public ActionResult ExportLanguageReport(LanguageRecord filters, string sortColumnName, string sortOrder, string hiddenColumns = null)
 {
     return(ExportReport(_queries.GetLanguageRecordsForExport(), filters, sortColumnName, sortOrder, hiddenColumns));
 }
Ejemplo n.º 6
0
        public ActionResult Add(string name, string login, string email, string address, string comment)
        {
            Debug($"Get ~/Administration/Customer/Add(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());
            }

            // check the value by itself

            Errors errors = new Errors();

            // no name set

            if (string.IsNullOrWhiteSpace(name))
            {
                errors.AddField("Name", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_NAME}" });
            }
            name = name.Trim();

            // no login set

            if (string.IsNullOrWhiteSpace(login))
            {
                errors.AddField("Login", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_LOGIN}" });
            }
            login = login.Trim();

            // no email set

            if (string.IsNullOrWhiteSpace(email))
            {
                errors.AddField("Email", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_EMAIL}" });
            }
            email = email.Trim();

            // check if the name already exists

            if (_userManager.Database.Customer.Where(c => c.Name.Equals(name)).Any())
            {
                errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_NAME}" });
            }

            // check if the login already exists

            bool loginExist = false;

            foreach (UserRecord record in _userManager.Database.User.Where(u => u.Login.Equals(login)).ToList())
            {
                // User deleted ?

                InformationRecord information = _userManager.Database._Information.FirstOrDefault(info => info.Id == record.Id && info.Table.Equals("User"));
                if (information == null || information.DeleteTick == null)
                {
                    loginExist = true;
                    break;
                }
            }

            if (loginExist)
            {
                errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_LOGIN}" });
            }

            // load ressources before designing the screen fitted to the user's profile

            LanguageDictionary ressources = new LanguageDictionary(Server.MapPath(LanguageDictionary.DIRECTORY_IMAGE), ConfigurationManager.DefaultLanguage);

            ressources.Load(_userManager.Database, user.CustomerId);

            if (errors.HasError)
            {
                // update ModelState on depends on errors

                SetModelState(ModelState, ressources, errors);
                return(View(new CustomerViewModel(ressources, user)));
            }

            // Create a new customer

            Info($"Creating of a new customer ('{name}', '{login}', '{email}', '{address}', '{comment}') ...");

            CustomerRecord newCustomer = new CustomerRecord()
            {
                Name    = name,
                Login   = login,
                Email   = email,
                Address = address,
                Comment = comment
            };

            _userManager.Database.Customer.Add(newCustomer);
            _userManager.Database.SaveChanges();

            Info($"Customer created {newCustomer}");

            // Add the parameter "Language.Tick.<customerId>" into the parameter table

            _userManager.Database._Parameter.Add(new ParameterRecord()
            {
                Key = $"Language.Tick.{newCustomer.Id}", Value = "0"
            });

            // Duplicate multilanguage dictionary (from the customer 1 to the new one)

            Info($"Duplicating multilanguage labels ...");

            int nbLabels = 0;

            foreach (LanguageRecord languageRecord in _userManager.Database.Language.Where(l => l.CustomerId == 1).ToList())
            {
                LanguageRecord newLanguageRecord = LanguageRecord.Copy(languageRecord) as LanguageRecord;
                newLanguageRecord.CustomerId = newCustomer.Id;
                _userManager.Database.Language.Add(newLanguageRecord);
                nbLabels++;
            }

            Info($"{nbLabels} labels duplicated");

            // Create the administrator for this new customer

            UserRecord newUser = new UserRecord()
            {
                Login        = login,
                Registration = name,
                Name         = name,
                Email        = email,
                Language     = user.Language,
                CustomerId   = newCustomer.Id
            };

            _userManager.Database.User.Add(newUser);
            _userManager.Database.SaveChanges();
            Info($"Creating a new user {newUser} ...");

            ModuleRecord newModule = new ModuleRecord()
            {
                Name       = "Administration",
                Module     = ModuleRecord.EModule.Administration,
                Profile    = UserProfile.EUserProfile.Administrator,
                Enable     = true,
                CustomerId = newCustomer.Id
            };

            _userManager.Database.Module.Add(newModule);
            _userManager.Database.SaveChanges();
            Info($"Module({newModule.Id}) created");

            UserModuleRecord newUserModule = new UserModuleRecord()
            {
                UserId     = newUser.Id,
                ModuleId   = newModule.Id,
                Default    = true,
                CustomerId = newCustomer.Id
            };

            _userManager.Database.UserModule.Add(newUserModule);
            _userManager.Database.SaveChanges();
            Info($"UserModule({newUserModule.Id}) created");

            // send a mail for the new user

            Info($"Sending an email to create the password ...");

            using (UserController controller = new UserController(_userManager))
                controller.SendNewPassword(newUser.Login);

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

            return(RedirectToAction("Index"));
        }