public ICollection <PostfixMailAddressDto> GetMailboxAddress(string mailbox_address) { const string domain_alias = "msd"; const string address_alias = "msa"; var address_query = PostfixCommonQueries.GetAddressJoinedWithDomainQuery(address_alias, domain_alias) .Where(AliasTable.Columns.redirect.Prefix(address_alias), mailbox_address) .Where(AliasTable.Columns.active.Prefix(address_alias), true) .Where(AliasTable.Columns.is_group.Prefix(address_alias), false); using (var db = _dbManager.GetAdminDb()) { var result = db.ExecuteList(address_query); return(result.Select(r => { const int address_length = ToDtoConverters.mail_address_columns_count; var address = r.SubArray(0, address_length).ToAddressDto(); var domain_info = r.SubArray(address_length, r.Length - address_length).ToWebDomainDto(); address.Domain = domain_info; return address; } ).ToList()); } }
private ICollection <PostfixMailAddressDto> _GetMembers(IDbManager db) { var members = new List <PostfixMailAddressDto>(); //Todo: Think about join this two queries var queryForJoinedGroupAddressSelection = new SqlQuery(AliasTable.name) .Select(AliasTable.Columns.redirect) .Where(AliasTable.Columns.address, Address.ToString()); var mailGroupAddresses = db.ExecuteScalar <string>(queryForJoinedGroupAddressSelection); if (null == mailGroupAddresses) { return(members); } var neededGroupAddresses = mailGroupAddresses.Split(','); const string address_alias = "msa"; var groupAddressesQuery = PostfixCommonQueries.GetAddressJoinedWithDomainQuery(address_alias, "msd") // ReSharper disable CoVariantArrayConversion .Where(Exp.In(AliasTable.Columns.address, neededGroupAddresses)); // ReSharper restore CoVariantArrayConversion var adressRecords = db.ExecuteList(groupAddressesQuery); foreach (var adressRecord in adressRecords) { var address = adressRecord.SubArray(0, ToDtoConverters.MAIL_ADDRESS_COLUMNS_COUNT).ToAddressDto(); var domain = adressRecord.SubArray(ToDtoConverters.MAIL_ADDRESS_COLUMNS_COUNT, ToDtoConverters.DOMAIN_COLUMNS_COUNT).ToWebDomainDto(); address.Domain = domain; members.Add(address); } return(members); }
protected override ICollection <MailGroupBase> _GetMailGroups(ICollection <string> mail_groups_addresses) { const string address_alias = "maa"; var mail_group_query = PostfixCommonQueries.GetAddressJoinedWithDomainQuery(address_alias, "mda") .Where(AliasTable.Columns.active.Prefix(address_alias), true) .Where(AliasTable.Columns.is_group.Prefix(address_alias), true) // ReSharper disable CoVariantArrayConversion .Where(Exp.In(AliasTable.Columns.address.Prefix(address_alias), mail_groups_addresses.ToArray())); // ReSharper restore CoVariantArrayConversion List <PostfixMailgroupDto> mailgroup_dto_list; using (var db = _dbManager.GetAdminDb()) { mailgroup_dto_list = db.ExecuteList(mail_group_query).ConvertAll(r => r.ToMailgroupDto()).ToList(); } return(mailgroup_dto_list .Select(mailgroup_dto => new MailGroupBase(mailgroup_dto.address.ToPostfixAddress(), new List <MailAddressBase>())) .ToList()); }