Esempio n. 1
0
 protected abstract MailGroupBase _DeleteMailGroup(MailGroupBase mailGroup);
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
 protected override MailGroupBase _DeleteMailGroup(MailGroupBase mailGroup)
 {
     _serverData.Groups.Remove(mailGroup);
     return mailGroup;
 }
Esempio n. 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;
 }
Esempio n. 5
0
        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;
        }