Ejemplo n.º 1
0
        public void DeleteDomain(int domain_id, DbManager db)
        {
            if (domain_id < 0)
            {
                throw new ArgumentException("Argument domain_id less then zero.", "domain_id");
            }

            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            const string group_alias   = "msg";
            const string address_alias = "msa";
            var          group_query   = new SqlQuery(MailGroupTable.name + " " + group_alias)
                                         .InnerJoin(AddressTable.name + " " + address_alias,
                                                    Exp.EqColumns(MailGroupTable.Columns.id_address.Prefix(group_alias),
                                                                  AddressTable.Columns.id.Prefix(address_alias)
                                                                  )
                                                    )
                                         .Select(MailGroupTable.Columns.id.Prefix(group_alias))
                                         .Where(AddressTable.Columns.tenant.Prefix(address_alias), tenant_id)
                                         .Where(AddressTable.Columns.id_domain.Prefix(address_alias), domain_id)
                                         .Where(AddressTable.Columns.is_mail_group.Prefix(address_alias), true);

            var mailbox_query = new SqlQuery(AddressTable.name)
                                .Select(AddressTable.Columns.id_mailbox)
                                .Where(AddressTable.Columns.tenant, tenant_id)
                                .Where(AddressTable.Columns.id_domain, domain_id)
                                .Where(AddressTable.Columns.is_mail_group, false)
                                .Where(AddressTable.Columns.is_alias, false);

            var delete_web_domain_query = new SqlDelete(DomainTable.name)
                                          .Where(DomainTable.Columns.tenant, tenant_id)
                                          .Where(DomainTable.Columns.id, domain_id);


            var result    = db.ExecuteList(group_query);
            var group_ids = result.Select(r => (int)r[0]).ToList();

            var group_dal = new MailGroupDal(tenant_id);

            foreach (var group_id in group_ids)
            {
                group_dal.DeleteMailGroup(group_id, db);
            }

            result = db.ExecuteList(mailbox_query);
            var mailbox_ids = result.Select(r => (int)r[0]).ToList();

            var mailbox_dal = new MailboxDal(tenant_id);

            foreach (var mailbox_id in mailbox_ids)
            {
                mailbox_dal.DeleteMailbox(mailbox_id, db);
            }

            db.ExecuteNonQuery(delete_web_domain_query);
        }
Ejemplo n.º 2
0
        public void DeleteDomain(int domainId, DbManager db)
        {
            if (domainId < 0)
            {
                throw new ArgumentException("Argument domain_id less then zero.", "domainId");
            }

            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            const string group_alias   = "msg";
            const string address_alias = "msa";
            var          groupQuery    = new SqlQuery(MailGroupTable.Name.Alias(group_alias))
                                         .InnerJoin(AddressTable.Name.Alias(address_alias),
                                                    Exp.EqColumns(MailGroupTable.Columns.AddressId.Prefix(group_alias),
                                                                  AddressTable.Columns.Id.Prefix(address_alias)
                                                                  )
                                                    )
                                         .Select(MailGroupTable.Columns.Id.Prefix(group_alias))
                                         .Where(AddressTable.Columns.Tenant.Prefix(address_alias), tenant)
                                         .Where(AddressTable.Columns.DomainId.Prefix(address_alias), domainId)
                                         .Where(AddressTable.Columns.IsMailGroup.Prefix(address_alias), true);

            var mailboxQuery = new SqlQuery(AddressTable.Name)
                               .Select(AddressTable.Columns.MailboxId)
                               .Where(AddressTable.Columns.Tenant, tenant)
                               .Where(AddressTable.Columns.DomainId, domainId)
                               .Where(AddressTable.Columns.IsMailGroup, false)
                               .Where(AddressTable.Columns.IsAlias, false);

            var deleteWebDomainQuery = new SqlDelete(DomainTable.Name)
                                       .Where(DomainTable.Columns.Tenant, tenant)
                                       .Where(DomainTable.Columns.Id, domainId);


            var result   = db.ExecuteList(groupQuery);
            var groupIds = result.Select(r => (int)r[0]).ToList();

            var groupDal = new MailGroupDal(tenant);

            foreach (var groupId in groupIds)
            {
                groupDal.DeleteMailGroup(groupId, db);
            }

            result = db.ExecuteList(mailboxQuery);
            var mailboxIds = result.Select(r => (int)r[0]).ToList();

            var mailboxDal = new MailboxDal(tenant);

            foreach (var mailboxId in mailboxIds)
            {
                mailboxDal.DeleteMailbox(mailboxId, db);
            }

            db.ExecuteNonQuery(deleteWebDomainQuery);
        }
Ejemplo n.º 3
0
        public MockServer(ServerSetup setup)
            : base(setup)
        {
            _serverData = MockServerData.GetInstance();

            _serverData.Domains.Clear();
            _serverData.Mailboxes.Clear();
            _serverData.Groups.Clear();

            _domainDal = new WebDomainDal(setup.Tenant);
            _mailboxDal = new MailboxDal(setup.Tenant, SetupInfo.Limits.MailboxMaxCountPerUser);
            _mailgroupDal = new MailGroupDal(setup.Tenant);
            _mailaddressDal = new MailAddressDal(setup.Tenant);

            var domains = _domainDal.GetTenantDomains();

            foreach (var domain in domains)
            {
                _serverData.Domains.Add(new WebDomainBase(domain.name));
            }

            var mailboxesDto = _mailboxDal.GetMailboxes();
            foreach (var mailboxDto in mailboxesDto)
            {
                var aliasList =
                    _mailaddressDal.GetMailboxAliases(mailboxDto.mailbox.id)
                                   .Select(
                                       aliasDto =>
                                       new MailAddressBase(aliasDto.name, new WebDomainBase(aliasDto.domain.name)))
                                   .ToList();

                var resultMailbox = new MailboxBase(
                    new MailAccountBase(mailboxDto.mailbox.address),
                    //Its not login. It adress. Needed only for testing
                    new MailAddressBase(mailboxDto.mailbox_address.name,
                                        new WebDomainBase(mailboxDto.mailbox_address.domain.name)), aliasList);

                _serverData.Mailboxes.Add(resultMailbox);
            }

            var groupsDto = _mailgroupDal.GetMailGroups();
            foreach (var resultGroup in from groupDto in groupsDto
                                        let groupAddresses = groupDto.addresses.Select(address =>
                                                                                       new MailAddressBase(address.name,
                                                                                                           new WebDomainBase
                                                                                                               (
                                                                                                               address
                                                                                                                   .domain
                                                                                                                   .name)))
                                                                     .ToList()
                                        select new MailGroupBase(
                                            new MailAddressBase(groupDto.address.name,
                                                                new WebDomainBase(groupDto.address.domain.name)),
                                            groupAddresses))
            {
                _serverData.Groups.Add(resultGroup);
            }
        }
Ejemplo n.º 4
0
        public void DeleteDomain(int domainId, DbManager db)
        {
            if (domainId < 0)
                throw new ArgumentException("Argument domain_id less then zero.", "domainId");
            
            if(db == null)
                throw new ArgumentNullException("db");

            const string group_alias = "msg";
            const string address_alias = "msa";
            var groupQuery = new SqlQuery(MailGroupTable.name + " " + group_alias)
                                .InnerJoin(AddressTable.name + " " + address_alias,
                                           Exp.EqColumns(MailGroupTable.Columns.id_address.Prefix(group_alias),
                                                         AddressTable.Columns.id.Prefix(address_alias)
                                                        )
                                          )
                                .Select(MailGroupTable.Columns.id.Prefix(group_alias))
                                .Where(AddressTable.Columns.tenant.Prefix(address_alias), tenant)
                                .Where(AddressTable.Columns.id_domain.Prefix(address_alias), domainId)
                                .Where(AddressTable.Columns.is_mail_group.Prefix(address_alias), true);

            var mailboxQuery = new SqlQuery(AddressTable.name)
                                .Select(AddressTable.Columns.id_mailbox)
                                .Where(AddressTable.Columns.tenant, tenant)
                                .Where(AddressTable.Columns.id_domain, domainId)
                                .Where(AddressTable.Columns.is_mail_group, false)
                                .Where(AddressTable.Columns.is_alias, false);

            var deleteWebDomainQuery = new SqlDelete(DomainTable.name)
                .Where(DomainTable.Columns.tenant, tenant)
                .Where(DomainTable.Columns.id, domainId);


            var result = db.ExecuteList(groupQuery);
            var groupIds = result.Select(r => (int)r[0]).ToList();

            var groupDal = new MailGroupDal(tenant);

            foreach (var groupId in groupIds)
            {
                groupDal.DeleteMailGroup(groupId, db);
            }

            result = db.ExecuteList(mailboxQuery);
            var mailboxIds = result.Select(r => (int)r[0]).ToList();

            var mailboxDal = new MailboxDal(tenant);

            foreach (var mailboxId in mailboxIds)
            {
                mailboxDal.DeleteMailbox(mailboxId, db);
            }

            db.ExecuteNonQuery(deleteWebDomainQuery);
        }