@@ -86,6 +86,11 @@ private List<EventRegistrationModel> GetAvailableEvents(string ref_id = null)
8686 if ( today >= e . StartDate )
8787 {
8888 EventRegistrationModel model = new EventRegistrationModel ( e ) ;
89+ model . NumberOfRegistration = erManager . GetAllRegistrationsNotDeletedByEvent ( e . Id ) . Count ;
90+ model . NrOfRegistrationWaitingList = erManager . GetAllWaitingListRegsByEvent ( e . Id ) . Count ;
91+
92+ model . Closed = e . Closed ;
93+
8994 //check if user already registered (if logged in)
9095 if ( user != null )
9196 {
@@ -482,6 +487,7 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
482487 using ( SubjectManager subManager = new SubjectManager ( ) )
483488 {
484489 using ( EventRegistrationManager erManager = new EventRegistrationManager ( ) )
490+ using ( var eventManager = new EventManager ( ) )
485491 {
486492 User user = subManager . Subjects . Where ( a => a . Name == HttpContext . User . Identity . Name ) . FirstOrDefault ( ) as User ;
487493 if ( user != null )
@@ -493,6 +499,9 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
493499 {
494500 reg . Deleted = true ;
495501 erManager . UpdateEventRegistration ( reg ) ;
502+ MoveFromWaitingList ( reg . Event . Id ) ;
503+
504+ SendEmailNotification ( "deleted" , user . Email , ref_id , reg . Data , reg . Event , user ) ;
496505 }
497506 }
498507 else if ( ref_id != null )
@@ -502,13 +511,83 @@ public ActionResult DeleteRegistration(string id, string ref_id = null)
502511 {
503512 reg . Deleted = true ;
504513 erManager . UpdateEventRegistration ( reg ) ;
514+ MoveFromWaitingList ( reg . Event . Id ) ;
515+
516+ SendEmailNotification ( "deleted" , user . Email , ref_id , reg . Data , reg . Event , user ) ;
505517 }
506518 }
507519 }
520+
521+
522+
523+
508524 }
509525 return Json ( new { result = "redirect" , url = Url . Action ( "EventRegistration" , "EventRegistration" , new { area = "EMM" } ) } , JsonRequestBehavior . AllowGet ) ;
510526 }
511527
528+ private void MoveFromWaitingList ( long eventId )
529+ {
530+ using ( var erManager = new EventRegistrationManager ( ) )
531+ using ( var eventManager = new EventManager ( ) )
532+ {
533+ int countWaitingList = erManager . GetAllWaitingListRegsByEvent ( eventId ) . Count ;
534+ if ( countWaitingList > 0 )
535+ {
536+ var reg = erManager . GetLatestWaitingListEntry ( eventId ) ;
537+ reg . WaitingList = false ;
538+ erManager . UpdateEventRegistration ( reg ) ;
539+ var e = eventManager . GetEventById ( eventId ) ;
540+ SendWaitingListNotification ( reg . Data , e ) ;
541+ }
542+ }
543+ }
544+
545+ private void SendWaitingListNotification ( XmlDocument data , Event e )
546+ {
547+ // todo: add not allowed / log in info to mail
548+
549+ EmailStructure emailStructure = new EmailStructure ( ) ;
550+ emailStructure = EmailHelper . ReadFile ( e . EventLanguage ) ;
551+
552+ string first_name = data . GetElementsByTagName ( emailStructure . lableFirstName ) [ 0 ] . InnerText ;
553+ string last_name = data . GetElementsByTagName ( emailStructure . lableLastname ) [ 0 ] . InnerText ;
554+ string email = data . GetElementsByTagName ( emailStructure . lableEmail ) [ 0 ] . InnerText ;
555+
556+ string url = Request . Url . GetLeftPart ( UriPartial . Authority ) ;
557+
558+ string mail_message = "" ;
559+ string subject = emailStructure . removeFromWaitingListSubject + e . Name ;
560+
561+ string body = emailStructure . bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
562+ emailStructure . removeFromWaitingList1 + "<br/><br/>" +
563+ emailStructure . bodyClosing + "<br/>" +
564+ emailStructure . bodyClosingName ;
565+
566+
567+ var es = new EmailService ( ) ;
568+
569+ // If no explicit Reply to mail is set use the SystemEmail
570+ string replyTo = "" ;
571+ if ( String . IsNullOrEmpty ( e . EmailReply ) )
572+ {
573+ replyTo = ConfigurationManager . AppSettings [ "SystemEmail" ] ;
574+ }
575+ else
576+ {
577+ replyTo = e . EmailReply ;
578+ }
579+
580+ es . Send (
581+ subject ,
582+ body ,
583+ new List < string > { email } , // to
584+ new List < string > { e . EmailCC } , // CC
585+ new List < string > { ConfigurationManager . AppSettings [ "SystemEmail" ] , e . EmailBCC } , // Allways send BCC to SystemEmail + additional set
586+ new List < string > { replyTo }
587+ ) ;
588+
589+ }
590+
512591 public ActionResult Save ( )
513592 {
514593 using ( EventManager eManager = new EventManager ( ) )
@@ -559,14 +638,14 @@ public ActionResult Save()
559638 {
560639 if ( e . EditAllowed != true )
561640 {
562- SendEmailNotification ( "resend" , email , ref_id , data , e , user ) ;
641+ SendEmailNotification ( "resend" , email , ref_id , XmlMetadataWriter . ToXmlDocument ( data ) , e , user ) ;
563642 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" } ) ;
564643 }
565644
566645 reg . Data = XmlMetadataWriter . ToXmlDocument ( data ) ;
567646 erManager . UpdateEventRegistration ( reg ) ;
568647
569- SendEmailNotification ( "updated" , email , ref_id , data , e , user ) ;
648+ SendEmailNotification ( "updated" , email , ref_id , XmlMetadataWriter . ToXmlDocument ( data ) , e , user ) ;
570649 }
571650 else
572651 CreateNewEventRegistration ( e , data , user , email , notificationType , ref_id ) ;
@@ -575,7 +654,6 @@ public ActionResult Save()
575654 else
576655 CreateNewEventRegistration ( e , data , user , email , notificationType , ref_id ) ;
577656
578-
579657 return Json ( new { result = "redirect" , url = Url . Action ( "EventRegistration" , "EventRegistration" , new { area = "EMM" , ref_id = ref_id } ) } , JsonRequestBehavior . AllowGet ) ;
580658 }
581659 }
@@ -587,15 +665,36 @@ public ActionResult Save()
587665 /// <returns></returns>
588666 private void CreateNewEventRegistration ( Event e , XDocument data , User user , string email , string notificationType , string ref_id )
589667 {
668+ bool waitingList = false ;
590669 using ( var erManager = new EventRegistrationManager ( ) )
670+ using ( var eventManager = new EventManager ( ) )
591671 {
592672 //check Participants Limitation
593673 if ( e . ParticipantsLimitation != 0 )
594674 {
595- int countRegs = erManager . GetNumerOfRegistrationsByEvent ( e . Id ) ;
675+ int countRegs = erManager . GetNumerOfRegistrationsByEvent ( e . Id ) + 1 ;
676+ int countWaitingList = erManager . GetAllWaitingListRegsByEvent ( e . Id ) . Count + 1 ;
677+
596678 if ( countRegs >= e . ParticipantsLimitation )
597679 {
598- notificationType = "succesfully_registered_waiting_list" ;
680+ if ( e . WaitingList && ! e . Closed )
681+ {
682+ if ( countWaitingList == e . WaitingListLimitation )
683+ {
684+ e . Closed = true ;
685+ eventManager . UpdateEvent ( e ) ;
686+ }
687+
688+ notificationType = "succesfully_registered_waiting_list" ;
689+ waitingList = true ;
690+
691+ }
692+ else
693+ {
694+ e . Closed = true ;
695+ eventManager . UpdateEvent ( e ) ;
696+ notificationType = "succesfully_registered" ;
697+ }
599698 }
600699 else
601700 {
@@ -607,10 +706,10 @@ private void CreateNewEventRegistration(Event e, XDocument data, User user, stri
607706 notificationType = "succesfully_registered" ;
608707 }
609708
610- // Save registration and send notification
611- erManager . CreateEventRegistration ( XmlMetadataWriter . ToXmlDocument ( data ) , e , user , false , ref_id ) ;
709+ // Save registration and send notification
710+ erManager . CreateEventRegistration ( XmlMetadataWriter . ToXmlDocument ( data ) , e , user , false , ref_id , waitingList , DateTime . Now ) ;
612711
613- SendEmailNotification ( notificationType , email , ref_id , data , e , user ) ;
712+ SendEmailNotification ( notificationType , email , ref_id , XmlMetadataWriter . ToXmlDocument ( data ) , e , user ) ;
614713 }
615714 }
616715
@@ -1077,19 +1176,15 @@ private EventRegistration CheckEventRegistration(User user, string ref_id, long
10771176 }
10781177 }
10791178
1080- 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 )
10811180 {
10821181 // todo: add not allowed / log in info to mail
10831182
1084- //temp for alb symosium
10851183 EmailStructure emailStructure = new EmailStructure ( ) ;
1086- if ( e . Id == 12 )
1087- emailStructure = EmailHelper . ReadFile ( "English" ) ;
1088- else
1089- emailStructure = EmailHelper . ReadFile ( e . EventLanguage ) ;
1184+ emailStructure = EmailHelper . ReadFile ( e . EventLanguage ) ;
10901185
1091- string first_name = XmlMetadataWriter . ToXmlDocument ( data ) . GetElementsByTagName ( emailStructure . lableFirstName ) [ 0 ] . InnerText ;
1092- 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 ;
10931188
10941189 string url = Request . Url . GetLeftPart ( UriPartial . Authority ) ;
10951190
@@ -1110,6 +1205,10 @@ private void SendEmailNotification(string notificationType, string email, string
11101205 subject = emailStructure . updateSubject + e . Name ;
11111206 mail_message = emailStructure . updateMessage + e . Name + ".<br/>" ;
11121207 break ;
1208+ case "deleted" :
1209+ subject = emailStructure . deletedSubject + e . Name ;
1210+ mail_message = emailStructure . deletedMessage + e . Name + ".<br/>" ;
1211+ break ;
11131212 //case "resend":
11141213 // subject = "Resend of registration confirmation for " + e.Name;
11151214 // mail_message = "your registration for " + e.Name + "<br/>";
@@ -1118,7 +1217,8 @@ private void SendEmailNotification(string notificationType, string email, string
11181217
11191218 string details = "" ;
11201219 //read xml file and format email output
1121- 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 ( ) )
11221222 {
11231223 string displayNameRoot = "" ;
11241224 if ( xe . HasElements )
@@ -1142,14 +1242,15 @@ private void SendEmailNotification(string notificationType, string email, string
11421242 }
11431243 }
11441244
1145- string body = emailStructure . bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
1245+ string body = emailStructure . bodyTitle + first_name + " " + last_name + ", " + "<br/><br/>" +
11461246
1147- mail_message + "<br/>" +
1148- e . MailInformation + "<br/>" +
1149- "<br/>" + emailStructure . bodyOpening + "<br/>" +
1150- details + "<br/><br/>" +
1151- emailStructure . bodyHintToLink + url + "/emm/EventRegistration/EventRegistration/?ref_id=" + ref_id + "<br/><br/>" +
1152- 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/>" +
11531254 emailStructure . bodyClosingName ;
11541255
11551256 var es = new EmailService ( ) ;
0 commit comments