Exemplo n.º 1
0
        public void RemoveEvent(ulong eventId, ObjectGuid remover)
        {
            CalendarEvent calendarEvent = GetEvent(eventId);

            if (calendarEvent == null)
            {
                SendCalendarCommandResult(remover, CalendarError.EventInvalid);
                return;
            }

            SendCalendarEventRemovedAlert(calendarEvent);

            SQLTransaction    trans = new SQLTransaction();
            PreparedStatement stmt;
            MailDraft         mail = new MailDraft(calendarEvent.BuildCalendarMailSubject(remover), calendarEvent.BuildCalendarMailBody());

            var eventInvites = _invites[eventId];

            for (int i = 0; i < eventInvites.Count; ++i)
            {
                CalendarInvite invite = eventInvites[i];
                stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CALENDAR_INVITE);
                stmt.AddValue(0, invite.InviteId);
                trans.Append(stmt);

                // guild events only? check invite status here?
                // When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki)
                if (!remover.IsEmpty() && invite.InviteeGuid != remover)
                {
                    mail.SendMailTo(trans, new MailReceiver(invite.InviteeGuid.GetCounter()), new MailSender(calendarEvent), MailCheckMask.Copied);
                }
            }

            _invites.Remove(eventId);

            stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CALENDAR_EVENT);
            stmt.AddValue(0, eventId);
            trans.Append(stmt);
            DB.Characters.CommitTransaction(trans);

            _events.Remove(calendarEvent);
        }