/// <summary> /// Set mailbox removed /// </summary> /// <param name="daoFactory"></param> /// <param name="mailBoxData"></param> /// <returns>Return freed quota value</returns> private static long RemoveMailBoxInfo(IDaoFactory daoFactory, MailBoxData mailBoxData) { if (mailBoxData.MailBoxId <= 0) { throw new Exception("MailBox id is 0"); } var daoMailbox = daoFactory.CreateMailboxDao(); var mailbox = daoMailbox.GetMailBox( new СoncreteUserMailboxExp(mailBoxData.MailBoxId, mailBoxData.TenantId, mailBoxData.UserId, null)); if (mailbox == null) { throw new Exception(string.Format("MailBox with id = {0} (Tenant={1}, User='******') not found", mailBoxData.MailBoxId, mailBoxData.TenantId, mailBoxData.UserId)); } daoMailbox.SetMailboxRemoved(mailbox); var daoChain = daoFactory.CreateChainDao(mailBoxData.TenantId, mailBoxData.UserId); var folderTypes = Enum.GetValues(typeof(FolderType)).Cast <int>().ToList(); daoChain.Delete( SimpleConversationsExp.CreateBuilder(mailBoxData.TenantId, mailBoxData.UserId) .SetFoldersIds(folderTypes) .SetMailboxId(mailBoxData.MailBoxId) .Build()); var daoCrmLink = daoFactory.CreateCrmLinkDao(mailBoxData.TenantId, mailBoxData.UserId); daoCrmLink.RemoveCrmLinks(mailBoxData.MailBoxId); var daoMailInfo = daoFactory.CreateMailInfoDao(mailBoxData.TenantId, mailBoxData.UserId); daoMailInfo.SetFieldValue( SimpleMessagesExp.CreateBuilder(mailBoxData.TenantId, mailBoxData.UserId) .SetMailboxId(mailBoxData.MailBoxId) .Build(), MailTable.Columns.IsRemoved, true); var exp = new ConcreteMailboxAttachmentsExp(mailBoxData.MailBoxId, mailBoxData.TenantId, mailBoxData.UserId, onlyEmbedded: null); var daoAttachment = daoFactory.CreateAttachmentDao(mailBoxData.TenantId, mailBoxData.UserId); var totalAttachmentsSize = daoAttachment.GetAttachmentsSize(exp); daoAttachment.SetAttachmnetsRemoved(exp); var tagDao = daoFactory.CreateTagDao(mailBoxData.TenantId, mailBoxData.UserId); var tagMailDao = daoFactory.CreateTagMailDao(mailBoxData.TenantId, mailBoxData.UserId); var tagIds = tagMailDao.GetTagIds(mailBoxData.MailBoxId); tagMailDao.DeleteByMailboxId(mailBoxData.MailBoxId); foreach (var tagId in tagIds) { var tag = tagDao.GetTag(tagId); if (tag == null) { continue; } var count = tagMailDao.CalculateTagCount(tag.Id); tag.Count = count; tagDao.SaveTag(tag); } daoFactory.CreateMailboxSignatureDao(mailBoxData.TenantId, mailBoxData.UserId).DeleteSignature(mailBoxData.MailBoxId); daoFactory.CreateMailboxAutoreplyDao(mailBoxData.TenantId, mailBoxData.UserId) .DeleteAutoreply(mailBoxData.MailBoxId); daoFactory.CreateMailboxAutoreplyHistoryDao(mailBoxData.TenantId, mailBoxData.UserId).DeleteAutoreplyHistory(mailBoxData.MailBoxId); daoFactory.CreateAlertDao(mailBoxData.TenantId, mailBoxData.UserId).DeleteAlerts(mailBoxData.MailBoxId); daoFactory.CreateUserFolderXMailDao(mailBoxData.TenantId, mailBoxData.UserId) .RemoveByMailbox(mailBoxData.MailBoxId); return(totalAttachmentsSize); }