Skip to content

Commit 5108df5

Browse files
Send mail for delete registration done and close #95
1 parent 1179d63 commit 5108df5

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

Controllers/EventRegistrationController.cs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
487487
using (SubjectManager subManager = new SubjectManager())
488488
{
489489
using (EventRegistrationManager erManager = new EventRegistrationManager())
490+
using (var eventManager = new EventManager())
490491
{
491492
User user = subManager.Subjects.Where(a => a.Name == HttpContext.User.Identity.Name).FirstOrDefault() as User;
492493
if (user != null)
@@ -500,6 +501,7 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
500501
erManager.UpdateEventRegistration(reg);
501502
MoveFromWaitingList(reg.Event.Id);
502503

504+
SendEmailNotification("deleted", user.Email, ref_id, reg.Data, reg.Event, user);
503505
}
504506
}
505507
else if (ref_id != null)
@@ -510,9 +512,15 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
510512
reg.Deleted = true;
511513
erManager.UpdateEventRegistration(reg);
512514
MoveFromWaitingList(reg.Event.Id);
515+
516+
SendEmailNotification("deleted", user.Email, ref_id, reg.Data, reg.Event, user);
513517
}
514518
}
515519
}
520+
521+
522+
523+
516524
}
517525
return Json(new { result = "redirect", url = Url.Action("EventRegistration", "EventRegistration", new { area = "EMM" }) }, JsonRequestBehavior.AllowGet);
518526
}
@@ -551,7 +559,7 @@ private void SendWaitingListNotification(XmlDocument data, Event e)
551559
string subject = emailStructure.removeFromWaitingListSubject + e.Name;
552560

553561
string body = emailStructure.bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
554-
emailStructure.removeFromWaitingList1 + e.Name + emailStructure.removeFromWaitingList2 + "<br/><br/>" +
562+
emailStructure.removeFromWaitingList1 + "<br/><br/>" +
555563
emailStructure.bodyClosing + "<br/>" +
556564
emailStructure.bodyClosingName;
557565

@@ -630,14 +638,14 @@ public ActionResult Save()
630638
{
631639
if (e.EditAllowed != true)
632640
{
633-
SendEmailNotification("resend", email, ref_id, data, e, user);
641+
SendEmailNotification("resend", email, ref_id, XmlMetadataWriter.ToXmlDocument(data), e, user);
634642
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" });
635643
}
636644

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

640-
SendEmailNotification("updated", email, ref_id, data, e, user);
648+
SendEmailNotification("updated", email, ref_id, XmlMetadataWriter.ToXmlDocument(data), e, user);
641649
}
642650
else
643651
CreateNewEventRegistration(e, data, user, email, notificationType, ref_id);
@@ -664,7 +672,7 @@ private void CreateNewEventRegistration(Event e, XDocument data, User user, stri
664672
//check Participants Limitation
665673
if (e.ParticipantsLimitation != 0)
666674
{
667-
int countRegs = erManager.GetNumerOfRegistrationsByEvent(e.Id);
675+
int countRegs = erManager.GetNumerOfRegistrationsByEvent(e.Id) + 1;
668676
int countWaitingList = erManager.GetAllWaitingListRegsByEvent(e.Id).Count + 1;
669677

670678
if (countRegs >= e.ParticipantsLimitation)
@@ -701,7 +709,7 @@ private void CreateNewEventRegistration(Event e, XDocument data, User user, stri
701709
// Save registration and send notification
702710
erManager.CreateEventRegistration(XmlMetadataWriter.ToXmlDocument(data), e, user, false, ref_id, waitingList, DateTime.Now);
703711

704-
SendEmailNotification(notificationType, email, ref_id, data, e, user);
712+
SendEmailNotification(notificationType, email, ref_id, XmlMetadataWriter.ToXmlDocument(data), e, user);
705713
}
706714
}
707715

@@ -1168,19 +1176,15 @@ private EventRegistration CheckEventRegistration(User user, string ref_id, long
11681176
}
11691177
}
11701178

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

1175-
//temp for alb symosium
11761183
EmailStructure emailStructure = new EmailStructure();
1177-
if(e.Id == 12)
1178-
emailStructure = EmailHelper.ReadFile("English");
1179-
else
1180-
emailStructure = EmailHelper.ReadFile(e.EventLanguage);
1184+
emailStructure = EmailHelper.ReadFile(e.EventLanguage);
11811185

1182-
string first_name = XmlMetadataWriter.ToXmlDocument(data).GetElementsByTagName(emailStructure.lableFirstName)[0].InnerText;
1183-
string last_name = XmlMetadataWriter.ToXmlDocument(data).GetElementsByTagName(emailStructure.lableLastname)[0].InnerText;
1186+
string first_name = data.GetElementsByTagName(emailStructure.lableFirstName)[0].InnerText;
1187+
string last_name = data.GetElementsByTagName(emailStructure.lableLastname)[0].InnerText;
11841188

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

@@ -1201,6 +1205,10 @@ private void SendEmailNotification(string notificationType, string email, string
12011205
subject = emailStructure.updateSubject + e.Name;
12021206
mail_message = emailStructure.updateMessage + e.Name + ".<br/>";
12031207
break;
1208+
case "deleted":
1209+
subject = emailStructure.deletedSubject + e.Name;
1210+
mail_message = emailStructure.deletedMessage + e.Name + ".<br/>";
1211+
break;
12041212
//case "resend":
12051213
// subject = "Resend of registration confirmation for " + e.Name;
12061214
// mail_message = "your registration for " + e.Name + "<br/>";
@@ -1209,7 +1217,8 @@ private void SendEmailNotification(string notificationType, string email, string
12091217

12101218
string details = "";
12111219
//read xml file and format email output
1212-
foreach (XElement xe in XElement.Parse(data.ToString()).Elements())
1220+
XDocument xDocument = XDocument.Parse(data.OuterXml);
1221+
foreach (XElement xe in XElement.Parse(xDocument.ToString()).Elements())
12131222
{
12141223
string displayNameRoot = "";
12151224
if (xe.HasElements)
@@ -1233,14 +1242,15 @@ private void SendEmailNotification(string notificationType, string email, string
12331242
}
12341243
}
12351244

1236-
string body = emailStructure.bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
1245+
string body = emailStructure.bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
12371246

1238-
mail_message + "<br/>" +
1239-
e.MailInformation + "<br/>" +
1240-
"<br/>" + emailStructure.bodyOpening +"<br/>" +
1241-
details + "<br/><br/>" +
1242-
emailStructure.bodyHintToLink + url + "/emm/EventRegistration/EventRegistration/?ref_id=" + ref_id + "<br/><br/>" +
1243-
emailStructure.bodyClosing + "<br/>" +
1247+
mail_message + "<br/>" +
1248+
e.MailInformation + "<br/>" +
1249+
"<br/>" + emailStructure.bodyOpening + "<br/>" +
1250+
details + "<br/><br/>";
1251+
if (notificationType != "deleted")
1252+
body += emailStructure.bodyHintToLink + url + "/emm/EventRegistration/EventRegistration/?ref_id=" + ref_id + "<br/><br/>";
1253+
body += emailStructure.bodyClosing + "<br/>" +
12441254
emailStructure.bodyClosingName;
12451255

12461256
var es = new EmailService();

Controllers/EventRegistrationResultController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void SendNotification(XmlDocument data, Event e)
187187
string subject = emailStructure.removeFromWaitingListSubject + e.Name;
188188

189189
string body = emailStructure.bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
190-
emailStructure.removeFromWaitingList1 + e.Name + emailStructure.removeFromWaitingList2 + "<br/><br/>" +
190+
emailStructure.removeFromWaitingList1 + "<br/><br/>" +
191191
emailStructure.bodyClosing + "<br/>" +
192192
emailStructure.bodyClosingName;
193193

Helper/EmailHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class EmailStructure
3838
public string bodyClosingName { get; set; }
3939
public string removeFromWaitingListSubject { get; set; }
4040
public string removeFromWaitingList1 { get; set; }
41-
public string removeFromWaitingList2 { get; set; }
41+
public string deletedSubject { get; set; }
42+
public string deletedMessage { get; set; }
4243

4344

4445
public EmailStructure()

0 commit comments

Comments
 (0)