Exemplo n.º 1
0
        public void CreateIfNotExist(IList <CreatePermissionRequest> pers)
        {
            using (App.Common.Data.IUnitOfWork uow = UnitOfWorkFactory.Create(Configuration.Current.Repository.DefaultConnectionStringName))
            {
                IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow);
                foreach (CreatePermissionRequest perRequest in pers)
                {
                    try
                    {
                        this.ValidateCreatePermissionRequest(perRequest);
                        Permission permission = new Permission(perRequest.Name, perRequest.Key, perRequest.Description);
                        perRepository.Add(permission);
                    }
                    catch (ValidationException ex)
                    {
                        if (ex.HasExceptionKey("security.addPermission.validation.nameAlreadyExist"))
                        {
                            continue;
                        }
                        if (ex.HasExceptionKey("security.addPermission.validation.keyAlreadyExist"))
                        {
                            continue;
                        }
                    }
                }

                uow.Commit();
            }
        }
Exemplo n.º 2
0
        public void CreateIfNotExist(IList <Role> roles)
        {
            using (App.Common.Data.IUnitOfWork uow = UnitOfWorkFactory.Create(Configuration.Current.Repository.DefaultConnectionStringName))
            {
                IRoleRepository roleRepository = IoC.Container.Resolve <IRoleRepository>(uow);
                foreach (Role role in roles)
                {
                    if (roleRepository.GetByKey(role.Key) != null)
                    {
                        continue;
                    }
                    roleRepository.Add(role);
                }

                uow.Commit();
            }
        }