Skip to content

Commit 1179d63

Browse files
move from waiting list #33
1 parent f5207b7 commit 1179d63

4 files changed

Lines changed: 82 additions & 2 deletions

File tree

Controllers/EventRegistrationController.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
498498
{
499499
reg.Deleted = true;
500500
erManager.UpdateEventRegistration(reg);
501+
MoveFromWaitingList(reg.Event.Id);
502+
501503
}
502504
}
503505
else if (ref_id != null)
@@ -507,13 +509,77 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
507509
{
508510
reg.Deleted = true;
509511
erManager.UpdateEventRegistration(reg);
512+
MoveFromWaitingList(reg.Event.Id);
510513
}
511514
}
512515
}
513516
}
514517
return Json(new { result = "redirect", url = Url.Action("EventRegistration", "EventRegistration", new { area = "EMM" }) }, JsonRequestBehavior.AllowGet);
515518
}
516519

520+
private void MoveFromWaitingList(long eventId)
521+
{
522+
using (var erManager = new EventRegistrationManager())
523+
using (var eventManager = new EventManager())
524+
{
525+
int countWaitingList = erManager.GetAllWaitingListRegsByEvent(eventId).Count;
526+
if (countWaitingList > 0)
527+
{
528+
var reg = erManager.GetLatestWaitingListEntry(eventId);
529+
reg.WaitingList = false;
530+
erManager.UpdateEventRegistration(reg);
531+
var e = eventManager.GetEventById(eventId);
532+
SendWaitingListNotification(reg.Data, e);
533+
}
534+
}
535+
}
536+
537+
private void SendWaitingListNotification(XmlDocument data, Event e)
538+
{
539+
// todo: add not allowed / log in info to mail
540+
541+
EmailStructure emailStructure = new EmailStructure();
542+
emailStructure = EmailHelper.ReadFile(e.EventLanguage);
543+
544+
string first_name = data.GetElementsByTagName(emailStructure.lableFirstName)[0].InnerText;
545+
string last_name = data.GetElementsByTagName(emailStructure.lableLastname)[0].InnerText;
546+
string email = data.GetElementsByTagName(emailStructure.lableEmail)[0].InnerText;
547+
548+
string url = Request.Url.GetLeftPart(UriPartial.Authority);
549+
550+
string mail_message = "";
551+
string subject = emailStructure.removeFromWaitingListSubject + e.Name;
552+
553+
string body = emailStructure.bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
554+
emailStructure.removeFromWaitingList1 + e.Name + emailStructure.removeFromWaitingList2 + "<br/><br/>" +
555+
emailStructure.bodyClosing + "<br/>" +
556+
emailStructure.bodyClosingName;
557+
558+
559+
var es = new EmailService();
560+
561+
// If no explicit Reply to mail is set use the SystemEmail
562+
string replyTo = "";
563+
if (String.IsNullOrEmpty(e.EmailReply))
564+
{
565+
replyTo = ConfigurationManager.AppSettings["SystemEmail"];
566+
}
567+
else
568+
{
569+
replyTo = e.EmailReply;
570+
}
571+
572+
es.Send(
573+
subject,
574+
body,
575+
new List<string> { email }, // to
576+
new List<string> { e.EmailCC }, // CC
577+
new List<string> { ConfigurationManager.AppSettings["SystemEmail"], e.EmailBCC }, // Allways send BCC to SystemEmail + additional set
578+
new List<string> { replyTo }
579+
);
580+
581+
}
582+
517583
public ActionResult Save()
518584
{
519585
using (EventManager eManager = new EventManager())
@@ -633,7 +699,7 @@ private void CreateNewEventRegistration(Event e, XDocument data, User user, stri
633699
}
634700

635701
// Save registration and send notification
636-
erManager.CreateEventRegistration(XmlMetadataWriter.ToXmlDocument(data), e, user, false, ref_id, waitingList);
702+
erManager.CreateEventRegistration(XmlMetadataWriter.ToXmlDocument(data), e, user, false, ref_id, waitingList, DateTime.Now);
637703

638704
SendEmailNotification(notificationType, email, ref_id, data, e, user);
639705
}

Entities/BExIS.Emm.Entities/Events/EventRegistration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class EventRegistration : BusinessEntity
2121

2222
public virtual bool WaitingList { get; set; }
2323

24+
public virtual DateTime InsertDate { get; set; }
25+
2426

2527
#endregion
2628

Orm/BExIS.Emm.Orm.NH/Mappings/Default/Event/EventRegistration.hbm.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
<property name="WaitingList" type="Boolean">
3636
<column name="WaitingList" />
3737
</property>
38+
39+
<property name="InsertDate" type="Date">
40+
<column name="InsertDate" />
41+
</property>
3842

3943
<!-- Mapping Entity Associations -->
4044

Services/BExIS.Emm.Services/Event/EventRegistrationManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected virtual void Dispose(bool disposing)
5858
/// <summary>
5959
/// Creates an EventRegistration <seealso cref="EventRegistration"/> and persists the entity in the database.
6060
/// </summary>
61-
public E.EventRegistration CreateEventRegistration(XmlDocument data, E.Event e, User user, bool deleted, string token, bool waitingList)
61+
public E.EventRegistration CreateEventRegistration(XmlDocument data, E.Event e, User user, bool deleted, string token, bool waitingList, DateTime insertDate)
6262
{
6363
E.EventRegistration eventRegistration = new E.EventRegistration();
6464
eventRegistration.Data = data;
@@ -67,6 +67,7 @@ public E.EventRegistration CreateEventRegistration(XmlDocument data, E.Event e,
6767
eventRegistration.Person = user;
6868
eventRegistration.Token= token;
6969
eventRegistration.WaitingList = waitingList;
70+
eventRegistration.InsertDate = insertDate;
7071

7172
using (IUnitOfWork uow = this.GetUnitOfWork())
7273
{
@@ -122,6 +123,13 @@ public E.EventRegistration UpdateEventRegistration(E.EventRegistration eventRegi
122123
return EventRegistrationRepo.Query(a => a.Event.Id == id && a.WaitingList == true && a.Deleted == false).ToList();
123124
}
124125

126+
public E.EventRegistration GetLatestWaitingListEntry(long id)
127+
{
128+
var lastestDates = EventRegistrationRepo.Query(d=>d.Event.Id == id && d.WaitingList == true).ToList();
129+
var date = lastestDates.Max(a => a.InsertDate);
130+
return EventRegistrationRepo.Query(a => a.Event.Id == id && a.WaitingList == true && a.InsertDate == date).FirstOrDefault();
131+
}
132+
125133

126134
public List<E.EventRegistration> GetAllRegistrationsNotDeletedByEvent(long id)
127135
{

0 commit comments

Comments
 (0)