Skip to content
Merged

Dev #96

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Controllers/EventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public ActionResult Save(EventModel model, HttpPostedFileBase file)

if (model.ImportantInformation == null)
ModelState.AddModelError("ImportantInformation", "Important information is required.");

if(model.ParticipantsLimitation == 0 && model.WaitingList == true)
ModelState.AddModelError("WaitingList", "You don't need a waiting list if there is no participants limitation.");

if (model.WaitingListLimitation > 0 && model.WaitingList == false)
ModelState.AddModelError("WaitingListLimitation", "You don't need a waiting list limitation if you dont use the waiting list.");


//check if schema file is uploaded
//if (attachments ==null &&model.Id == 0)
Expand All @@ -134,7 +141,7 @@ public ActionResult Save(EventModel model, HttpPostedFileBase file)

if (model.Id == 0)
{
Event newEvent = eManager.CreateEvent(model.Name, model.EventDate, model.ImportantInformation, model.MailInformation, model.SelectedEventLanguage, model.StartDate, model.Deadline, model.ParticipantsLimitation, model.EditAllowed, model.LogInPassword, model.EmailBCC, model.EmailCC, model.EmailReply, ms, null);
Event newEvent = eManager.CreateEvent(model.Name, model.EventDate, model.ImportantInformation, model.MailInformation, model.SelectedEventLanguage, model.StartDate, model.Deadline, model.ParticipantsLimitation, model.WaitingList,model.WaitingListLimitation, model.EditAllowed, model.Closed, model.LogInPassword, model.EmailBCC, model.EmailCC, model.EmailReply, ms, null);

newEvent = SaveFile(file, newEvent, eManager);
eManager.UpdateEvent(newEvent);
Expand Down Expand Up @@ -172,7 +179,10 @@ public ActionResult Save(EventModel model, HttpPostedFileBase file)
e.StartDate = model.StartDate;
e.Deadline = model.Deadline;
e.ParticipantsLimitation = model.ParticipantsLimitation;
e.WaitingList = model.WaitingList;
e.WaitingListLimitation = model.WaitingListLimitation;
e.EditAllowed = model.EditAllowed;
e.Closed = model.Closed;
e.LogInPassword = model.LogInPassword;
e.LogInPassword = model.LogInPassword;
e.EmailCC = model.EmailCC;
Expand All @@ -184,7 +194,7 @@ public ActionResult Save(EventModel model, HttpPostedFileBase file)
eManager.UpdateEvent(e);
}

return View("EventManager");
return RedirectToAction("EventManager");
}
}
else
Expand Down
149 changes: 125 additions & 24 deletions Controllers/EventRegistrationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ private List<EventRegistrationModel> GetAvailableEvents(string ref_id = null)
if (today >= e.StartDate)
{
EventRegistrationModel model = new EventRegistrationModel(e);
model.NumberOfRegistration = erManager.GetAllRegistrationsNotDeletedByEvent(e.Id).Count;
model.NrOfRegistrationWaitingList = erManager.GetAllWaitingListRegsByEvent(e.Id).Count;

model.Closed = e.Closed;

//check if user already registered (if logged in)
if (user != null)
{
Expand Down Expand Up @@ -482,6 +487,7 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
using (SubjectManager subManager = new SubjectManager())
{
using (EventRegistrationManager erManager = new EventRegistrationManager())
using (var eventManager = new EventManager())
{
User user = subManager.Subjects.Where(a => a.Name == HttpContext.User.Identity.Name).FirstOrDefault() as User;
if (user != null)
Expand All @@ -493,6 +499,9 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
{
reg.Deleted = true;
erManager.UpdateEventRegistration(reg);
MoveFromWaitingList(reg.Event.Id);

SendEmailNotification("deleted", user.Email, ref_id, reg.Data, reg.Event, user);
}
}
else if (ref_id != null)
Expand All @@ -502,13 +511,83 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
{
reg.Deleted = true;
erManager.UpdateEventRegistration(reg);
MoveFromWaitingList(reg.Event.Id);

SendEmailNotification("deleted", user.Email, ref_id, reg.Data, reg.Event, user);
}
}
}




}
return Json(new { result = "redirect", url = Url.Action("EventRegistration", "EventRegistration", new { area = "EMM" }) }, JsonRequestBehavior.AllowGet);
}

private void MoveFromWaitingList(long eventId)
{
using (var erManager = new EventRegistrationManager())
using (var eventManager = new EventManager())
{
int countWaitingList = erManager.GetAllWaitingListRegsByEvent(eventId).Count;
if (countWaitingList > 0)
{
var reg = erManager.GetLatestWaitingListEntry(eventId);
reg.WaitingList = false;
erManager.UpdateEventRegistration(reg);
var e = eventManager.GetEventById(eventId);
SendWaitingListNotification(reg.Data, e);
}
}
}

private void SendWaitingListNotification(XmlDocument data, Event e)
{
// todo: add not allowed / log in info to mail

EmailStructure emailStructure = new EmailStructure();
emailStructure = EmailHelper.ReadFile(e.EventLanguage);

string first_name = data.GetElementsByTagName(emailStructure.lableFirstName)[0].InnerText;
string last_name = data.GetElementsByTagName(emailStructure.lableLastname)[0].InnerText;
string email = data.GetElementsByTagName(emailStructure.lableEmail)[0].InnerText;

string url = Request.Url.GetLeftPart(UriPartial.Authority);

string mail_message = "";
string subject = emailStructure.removeFromWaitingListSubject + e.Name;

string body = emailStructure.bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
emailStructure.removeFromWaitingList1 + "<br/><br/>" +
emailStructure.bodyClosing + "<br/>" +
emailStructure.bodyClosingName;


var es = new EmailService();

// If no explicit Reply to mail is set use the SystemEmail
string replyTo = "";
if (String.IsNullOrEmpty(e.EmailReply))
{
replyTo = ConfigurationManager.AppSettings["SystemEmail"];
}
else
{
replyTo = e.EmailReply;
}

es.Send(
subject,
body,
new List<string> { email }, // to
new List<string> { e.EmailCC }, // CC
new List<string> { ConfigurationManager.AppSettings["SystemEmail"], e.EmailBCC }, // Allways send BCC to SystemEmail + additional set
new List<string> { replyTo }
);

}

public ActionResult Save()
{
using (EventManager eManager = new EventManager())
Expand Down Expand Up @@ -559,14 +638,14 @@ public ActionResult Save()
{
if (e.EditAllowed != true)
{
SendEmailNotification("resend", email, ref_id, data, e, user);
SendEmailNotification("resend", email, ref_id, XmlMetadataWriter.ToXmlDocument(data), e, user);
return RedirectToAction("EventRegistrationPatial", new { message = "Update of your previous registration is not allowed. You registration details are send to your Email adress again.", message_type = "error" });
}

reg.Data = XmlMetadataWriter.ToXmlDocument(data);
erManager.UpdateEventRegistration(reg);

SendEmailNotification("updated", email, ref_id, data, e, user);
SendEmailNotification("updated", email, ref_id, XmlMetadataWriter.ToXmlDocument(data), e, user);
}
else
CreateNewEventRegistration(e, data, user, email, notificationType, ref_id);
Expand All @@ -575,7 +654,6 @@ public ActionResult Save()
else
CreateNewEventRegistration(e, data, user, email, notificationType, ref_id);


return Json(new { result = "redirect", url = Url.Action("EventRegistration", "EventRegistration", new { area = "EMM", ref_id = ref_id }) }, JsonRequestBehavior.AllowGet);
}
}
Expand All @@ -587,15 +665,36 @@ public ActionResult Save()
/// <returns></returns>
private void CreateNewEventRegistration(Event e, XDocument data, User user, string email, string notificationType, string ref_id)
{
bool waitingList = false;
using (var erManager = new EventRegistrationManager())
using(var eventManager = new EventManager())
{
//check Participants Limitation
if (e.ParticipantsLimitation != 0)
{
int countRegs = erManager.GetNumerOfRegistrationsByEvent(e.Id);
int countRegs = erManager.GetNumerOfRegistrationsByEvent(e.Id) + 1;
int countWaitingList = erManager.GetAllWaitingListRegsByEvent(e.Id).Count + 1;

if (countRegs >= e.ParticipantsLimitation)
{
notificationType = "succesfully_registered_waiting_list";
if(e.WaitingList && !e.Closed)
{
if(countWaitingList == e.WaitingListLimitation)
{
e.Closed = true;
eventManager.UpdateEvent(e);
}

notificationType = "succesfully_registered_waiting_list";
waitingList = true;

}
else
{
e.Closed = true;
eventManager.UpdateEvent(e);
notificationType = "succesfully_registered";
}
}
else
{
Expand All @@ -607,10 +706,10 @@ private void CreateNewEventRegistration(Event e, XDocument data, User user, stri
notificationType = "succesfully_registered";
}

// Save registration and send notification
erManager.CreateEventRegistration(XmlMetadataWriter.ToXmlDocument(data), e, user, false, ref_id);
// Save registration and send notification
erManager.CreateEventRegistration(XmlMetadataWriter.ToXmlDocument(data), e, user, false, ref_id, waitingList, DateTime.Now);

SendEmailNotification(notificationType, email, ref_id, data, e, user);
SendEmailNotification(notificationType, email, ref_id, XmlMetadataWriter.ToXmlDocument(data), e, user);
}
}

Expand Down Expand Up @@ -1077,19 +1176,15 @@ private EventRegistration CheckEventRegistration(User user, string ref_id, long
}
}

private void SendEmailNotification(string notificationType, string email, string ref_id, XDocument data, Event e, User user)
private void SendEmailNotification(string notificationType, string email, string ref_id, XmlDocument data, Event e, User user)
{
// todo: add not allowed / log in info to mail

//temp for alb symosium
EmailStructure emailStructure = new EmailStructure();
if(e.Id == 12)
emailStructure = EmailHelper.ReadFile("English");
else
emailStructure = EmailHelper.ReadFile(e.EventLanguage);
emailStructure = EmailHelper.ReadFile(e.EventLanguage);

string first_name = XmlMetadataWriter.ToXmlDocument(data).GetElementsByTagName(emailStructure.lableFirstName)[0].InnerText;
string last_name = XmlMetadataWriter.ToXmlDocument(data).GetElementsByTagName(emailStructure.lableLastname)[0].InnerText;
string first_name = data.GetElementsByTagName(emailStructure.lableFirstName)[0].InnerText;
string last_name = data.GetElementsByTagName(emailStructure.lableLastname)[0].InnerText;

string url = Request.Url.GetLeftPart(UriPartial.Authority);

Expand All @@ -1110,6 +1205,10 @@ private void SendEmailNotification(string notificationType, string email, string
subject = emailStructure.updateSubject + e.Name;
mail_message = emailStructure.updateMessage + e.Name + ".<br/>";
break;
case "deleted":
subject = emailStructure.deletedSubject + e.Name;
mail_message = emailStructure.deletedMessage + e.Name + ".<br/>";
break;
//case "resend":
// subject = "Resend of registration confirmation for " + e.Name;
// mail_message = "your registration for " + e.Name + "<br/>";
Expand All @@ -1118,7 +1217,8 @@ private void SendEmailNotification(string notificationType, string email, string

string details = "";
//read xml file and format email output
foreach (XElement xe in XElement.Parse(data.ToString()).Elements())
XDocument xDocument = XDocument.Parse(data.OuterXml);
foreach (XElement xe in XElement.Parse(xDocument.ToString()).Elements())
{
string displayNameRoot = "";
if (xe.HasElements)
Expand All @@ -1142,14 +1242,15 @@ private void SendEmailNotification(string notificationType, string email, string
}
}

string body = emailStructure.bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
string body = emailStructure.bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +

mail_message + "<br/>" +
e.MailInformation + "<br/>" +
"<br/>" + emailStructure.bodyOpening +"<br/>" +
details + "<br/><br/>" +
emailStructure.bodyHintToLink + url + "/emm/EventRegistration/EventRegistration/?ref_id=" + ref_id + "<br/><br/>" +
emailStructure.bodyClosing + "<br/>" +
mail_message + "<br/>" +
e.MailInformation + "<br/>" +
"<br/>" + emailStructure.bodyOpening + "<br/>" +
details + "<br/><br/>";
if (notificationType != "deleted")
body += emailStructure.bodyHintToLink + url + "/emm/EventRegistration/EventRegistration/?ref_id=" + ref_id + "<br/><br/>";
body += emailStructure.bodyClosing + "<br/>" +
emailStructure.bodyClosingName;

var es = new EmailService();
Expand Down
Loading