コード例 #1
0
ファイル: ServerModel.cs プロジェクト: vipwan/CommunityServer
 protected abstract MailGroupBase _DeleteMailGroup(MailGroupBase mailGroup);
コード例 #2
0
ファイル: ServerModel.cs プロジェクト: vipwan/CommunityServer
        public override IMailGroup CreateMailGroup(string groupName, IWebDomain domain, List<int> addressIds, IMailServerFactory factory)
        {
            if (string.IsNullOrEmpty(groupName))
                throw new ArgumentNullException("groupName", "ServerModel::CreateMailGroup");

            if (domain == null)
                throw new ArgumentNullException("domain");

            if (addressIds == null)
                throw new ArgumentNullException("addressIds");

            if(!addressIds.Any())
                throw new ArgumentException("Empty address_ids list");

            if (factory == null)
                throw new ArgumentNullException("factory");

            MailGroupDto mailgroupDto;

            using (var dbContextWithTran = TeamlabMailGroupDal.CreateMailDbContext(true))
            {
                var addressDtoList = TeamlabMailAddressDal.GetMailAddresses(addressIds, dbContextWithTran.DbManager);

                var addressBaseList =
                    addressDtoList
                        .Select(dto =>
                                new MailAddressBase(dto.name,
                                                    new WebDomainBase(dto.domain.name)))
                        .ToList();

                var mailgroupBase = new MailGroupBase(new MailAddressBase(groupName, new WebDomainBase(domain)),
                                                       addressBaseList);
                mailgroupDto = TeamlabMailGroupDal.SaveMailGroup(mailgroupBase.Address.LocalPart,
                                                                  mailgroupBase.Address.DateCreated,
                                                                  domain.Id,
                                                                  domain.Name,
                                                                  domain.IsVerified,
                                                                  addressDtoList, dbContextWithTran.DbManager);
                _CreateMailGroup(mailgroupBase.Address, addressBaseList);

                dbContextWithTran.CommitTransaction();
            }

            var mailgroupAddress = factory.CreateMailAddress(mailgroupDto.address.id, mailgroupDto.address.tenant, mailgroupDto.address.name, domain);

            var inAddresses =
                mailgroupDto.addresses.Select(
                    addressDto => factory.CreateMailAddress(addressDto.id, addressDto.tenant, addressDto.name, domain))
                               .ToList();

            var mailgroup = factory.CreateMailGroup(mailgroupDto.id, mailgroupDto.id_tenant, 
                mailgroupAddress, inAddresses.ToList(), this);

            return mailgroup;
        }
コード例 #3
0
ファイル: MockServer.cs プロジェクト: vipwan/CommunityServer
 protected override MailGroupBase _DeleteMailGroup(MailGroupBase mailGroup)
 {
     _serverData.Groups.Remove(mailGroup);
     return mailGroup;
 }
コード例 #4
0
 protected override MailGroupBase _DeleteMailGroup(MailGroupBase mailGroup)
 {
     var mailgroupDeleteQuery = new SqlDelete(AliasTable.name)
         .Where(AliasTable.Columns.address, mailGroup.Address.ToString());
     int rowsDeleted;
     using (var db = _dbManager.GetAdminDb())
     {
         rowsDeleted = db.ExecuteNonQuery(mailgroupDeleteQuery);
         if (rowsDeleted > 1)
         {
             var m = String.Format("Invalid addresses count was deleted: {0}. Address: {1}", rowsDeleted, mailGroup.Address);
             throw new InvalidOperationException(m);
         }
     }
     return rowsDeleted == 0 ? null: mailGroup;
 }
コード例 #5
0
ファイル: MockServer.cs プロジェクト: vipwan/CommunityServer
        protected override MailGroupBase _CreateMailGroup(MailAddressBase address, List<MailAddressBase> mailboxAddressList)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address", "MockServer::_CreateMailGroup");
            }

            if (_serverData.Groups.Any(r => r.Address.ToString().Equals(address.ToString())))
            {
                throw new ArgumentException();
            }

            var resultGroup =  new MailGroupBase(address, mailboxAddressList);
            _serverData.Groups.Add(resultGroup);
            return resultGroup;
        }