public ThreadTO updateMessageThread(string pwd, Int32 threadId, string threadSubject, Int32 messageCategory, Int32 threadOplock)
{
ThreadTO result = new ThreadTO();
if (threadId <= 0)
{
result.fault = new FaultTO("Must specify a message thread");
}
else if (String.IsNullOrEmpty(threadSubject))
{
result.fault = new FaultTO("Missing thread subject");
}
else if (messageCategory > 0 && !Enum.IsDefined(typeof(gov.va.medora.mdo.domain.sm.enums.MessageCategoryTypeEnum), messageCategory))
{
result.fault = new FaultTO("That message category is not defined");
}
if (result.fault != null)
{
return result;
}
try
{
gov.va.medora.mdo.domain.sm.Thread thread = new gov.va.medora.mdo.domain.sm.Thread()
{
Id = threadId,
Subject = threadSubject,
MessageCategoryType = (gov.va.medora.mdo.domain.sm.enums.MessageCategoryTypeEnum)messageCategory,
Oplock = threadOplock
};
using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
{
SecureMessageDao dao = new SecureMessageDao(cxn);
gov.va.medora.mdo.domain.sm.Thread dbThread = dao.getMessagesFromThread(threadId);
// we don't want to permit apps to change the mail group this way so just keep what's in the database which gets set through the proper channels
thread.MailGroup = dbThread.MailGroup;
if (dbThread == null || dbThread.Id <= 0 || dbThread.Messages == null || dbThread.Messages.Count <= 0)
{
throw new Exception("That thread does not exist in the database or appears malformed");
}
// make sure the thread hasn't been marked as completed
foreach(Message m in dbThread.Messages)
{
if (m.CompletedDate.Year > 1900)
{
throw new Exception("That message thread has already been completed. Unable to edit.");
}
}
result = new ThreadTO(dao.updateThread(thread));
}
}
catch (Exception exc)
{
result.fault = new FaultTO(exc);
}
return result;
}