// get all events as list and optional by user public ActionResult GetEventsAsList(string myBookings, string history = "false") { List <BookingEventModel> model = new List <BookingEventModel>(); List <BookingEvent> eventList = new List <BookingEvent>(); // Get all events optional filtered by user if (bool.Parse(history) == true) { eventList = GetAllEventsFiltered(bool.Parse(myBookings)); // gut full list with history ViewBag.history = "true"; } else { eventList = GetAllEventsFiltered(bool.Parse(myBookings), DateTime.Now.AddDays(-1).ToString()); // get list without historical events ViewBag.history = "false"; } // Remove dublicate booking events in resources list (without filter not dublicates, but with) eventList = eventList.GroupBy(x => x.Id).Select(x => x.First()).ToList(); foreach (BookingEvent e in eventList) { BookingEventModel m = new BookingEventModel(e); m.startDate = m.Schedules.Select(a => a.ScheduleDurationModel.StartDate).ToList().Min(); m.endDate = m.Schedules.Select(a => a.ScheduleDurationModel.EndDate).ToList().Max(); m.ResourceName = string.Join <string>(",", (m.Schedules.Select(a => a.ResourceName)).ToList()); List <string> attributes = new List <string>(); foreach (var c in m.Schedules.Select(a => a.ResourceAttributeValues).ToList()) { // Assumption the first attribute (domain value) is of importance -> show it in the list ResourceAttributeValue value = c.First(); if (value is TextValue) { TextValue tv = (TextValue)value; attributes.Add(tv.Value.ToString()); } } m.ResourceAttributes = string.Join <string>(",", attributes.Distinct()); model.Add(m); } //model = model.OrderByDescending(a => a.startDate).ToList(); return(PartialView("_listEvents", model)); }
/// <summary> /// Send a booking notification (create, edit or delete event) as email to in config file defined receivers /// </summary> /// <param name="bookingAction">For which action the notification will be send. (create, edit or delete event)</param> /// <returns></returns> /// <remarks></remarks> public static void SendBookingNotification(BookingAction bookingAction, BookingEventModel model) { //get receiver and sender from the settings file var receiver = Modules.RBM.UI.Helper.Settings.get("BookingMailReceiver").ToString().Split(',').ToList(); var receiverCC = Modules.RBM.UI.Helper.Settings.get("BookingMailReceiverCC").ToString().Split(',').ToList(); var receiverBCC = Modules.RBM.UI.Helper.Settings.get("BookingMailReceiverBCC").ToString().Split(',').ToList(); var sender = Modules.RBM.UI.Helper.Settings.get("BookingMailSender").ToString(); var subject = Modules.RBM.UI.Helper.Settings.get("BookingMailSubject").ToString() + ": " + bookingAction; string message = ""; message += "<p>The following booking has been " + bookingAction + "</p>"; message += "<b>Booking name: </b>" + model.Name + "</br>"; if (!String.IsNullOrEmpty(model.Description)) { message += "<b>Booking description: </b> " + model.Description + "</br>"; } message += "<p><b>Booked Resources:</b></p>"; using (var userManager = new UserManager()) using (var partyManager = new PartyManager()) { foreach (ScheduleEventModel schedule in model.Schedules) { message += "<b>Resource: </b>" + schedule.ResourceName + "</br>"; message += "<b>Start date: </b>" + schedule.ScheduleDurationModel.StartDate.ToString("dd.MM.yyyy") + "</br>"; message += "<b>End date: </b>" + schedule.ScheduleDurationModel.EndDate.ToString("dd.MM.yyyy") + "</br>"; message += "<b>Reserved by: </b>" + schedule.ByPerson + "</br>"; message += "<b>Contact person: </b>" + schedule.ContactName + " ( #" + schedule.Contact.MobileNumber + ")</br>"; message += "<b>Reserved for: </b>"; foreach (PersonInSchedule person in schedule.ForPersons) { if (schedule.ForPersons.IndexOf(person) == schedule.ForPersons.Count - 1) { message += person.UserFullName; } else { message += person.UserFullName + ", "; } var user = userManager.FindByIdAsync(person.UserId).Result; if (user != null) { receiver.Add(user.Email); } } message += "</br></br>"; } } receiverBCC.Add(ConfigurationManager.AppSettings["SystemEmail"].ToString()); // Allways send BCC to SystemEmail var emailService = new EmailService(); emailService.Send( subject, message, receiver.Distinct().ToList(), receiverCC, receiverBCC ); }