public int UpdateSurvey(Survey survey)
{
int moduleId;
Survey surveyToUpdate;
var surveyRepository = new SurveyRepository();
if (survey.SurveyId > 0)
{
surveyToUpdate = surveyRepository.LoadSurvey(survey.SurveyId);
surveyToUpdate.RevisingUser = surveyToUpdate.Sections[0].RevisingUser = survey.RevisingUser;
moduleId = surveyToUpdate.ModuleId;
}
else
{
surveyToUpdate = surveyRepository.CreateSurvey(survey.RevisingUser, survey.PortalId, survey.ModuleId);
moduleId = survey.ModuleId;
}
if (!this.CanEditModule(moduleId))
{
this.DenyAccess();
}
// TODO: store dates in UTC
surveyToUpdate.Text = survey.Text;
surveyToUpdate.PortalId = survey.PortalId;
surveyToUpdate.ModuleId = survey.ModuleId;
surveyToUpdate.ShowText = true;
surveyToUpdate.StartDate = survey.StartDate;
surveyToUpdate.PreStartMessage = survey.PreStartMessage;
surveyToUpdate.EndDate = survey.EndDate;
surveyToUpdate.PostEndMessage = survey.PostEndMessage;
surveyToUpdate.SendNotification = survey.SendNotification;
surveyToUpdate.NotificationFromEmailAddress = survey.NotificationFromEmailAddress;
surveyToUpdate.NotificationToEmailAddresses = survey.NotificationToEmailAddresses;
surveyToUpdate.SendThankYou = survey.SendThankYou;
surveyToUpdate.ThankYouFromEmailAddress = survey.ThankYouFromEmailAddress;
surveyToUpdate.FinalMessageOption = survey.FinalMessageOption;
surveyToUpdate.FinalMessage = survey.FinalMessage;
surveyToUpdate.FinalUrl = survey.FinalUrl;
surveyToUpdate.Sections.First().Text = survey.Sections.First().Text;
surveyToUpdate.Sections.First().ShowText = true;
surveyRepository.SubmitChanges();
return surveyToUpdate.SurveyId;
}