public object Post(Reservation reservation)
 {
     Check.NotNull(reservation, "reservation");
     var id = reservationEngine.AddReservation(reservation);
     NotificationEmail.Send(reservation);
     return new { Id = id };
 }
Beispiel #2
0
        public void ChangeReservation(Guid id, Reservation updatedReservation)
        {
            CheckOwnership(id);
            CheckReservation(updatedReservation, id);

            repository.Save(id, updatedReservation);
        }
Beispiel #3
0
        private static void CheckForReservations()
        {
            var user = new User("mircea.nistor", "Mircea Nistor", "*****@*****.**");

            var reservation = new Reservation(user, "Daily LPL Meeting", new DateTime(2013, 9, 13), new DateTime(2013, 9, 13).AddHours(1));
            reservation.AddParticipant(user);
            NotificationEmail.Send(reservation);
        }
Beispiel #4
0
        public static void Send(Reservation res)
        {
            using (SmtpClient client = new SmtpClient())
            {
                var host = ConfigurationManager.AppSettings["Croom.Email.Host"];

                if (!string.IsNullOrWhiteSpace(host))
                {
                    client.Host = host;
                }

                using (var message = CreateMessage(res))
                {
                    client.Send(message);
                }
            }
        }
Beispiel #5
0
 private static string FormatBody(Reservation res)
 {
     string htmlTemplate = string.Empty;
     string path = string.Format("{0}NotificationTemplate.html", AppDomain.CurrentDomain.BaseDirectory);
     using (StreamReader sReader = new StreamReader(path))
     {
         htmlTemplate = sReader.ReadToEnd();
         htmlTemplate = htmlTemplate.Replace("[DayName]", GetDayName(res.StartsAt));
         htmlTemplate = htmlTemplate.Replace("[StartDate]", res.StartsAt.ToString());
         htmlTemplate = htmlTemplate.Replace("[ReservationTitle]", res.Title);
         htmlTemplate = htmlTemplate.Replace("[ReservationDescription]", res.Description);
         htmlTemplate = htmlTemplate.Replace("[Participants]", GetParticipants(res));
         htmlTemplate = htmlTemplate.Replace("[Comments]", GetComments(res));
         htmlTemplate = htmlTemplate.Replace("[RequestedBy]", res.RequestedBy.FullName);
         htmlTemplate = htmlTemplate.Replace("[LastsFor]", res.LastsFor.ToString());
     }
     return htmlTemplate;
 }
Beispiel #6
0
        private static MailMessage CreateMessage(Reservation res)
        {
            var message = new MailMessage();

            message.From = new MailAddress(ConfigurationManager.AppSettings["Croom.Email.From"]);

            message.To.Add(new MailAddress(res.RequestedBy.Email));

            foreach (var participant in res.Participants)
            {
                if (!string.IsNullOrWhiteSpace(participant.Email))
                {
                    message.To.Add(new MailAddress(participant.Email));
                }
            }

            message.Subject = FormatSubject(res);
            message.Body = FormatBody(res);
            message.IsBodyHtml = true;
            //message.Priority

            return message;
        }
Beispiel #7
0
 public void Save(Guid id, Reservation updatedReservation)
 {
     dataStore.SaveOrUpdate(new KeyValuePair<Guid, object>(id, updatedReservation));
 }
Beispiel #8
0
 public Guid Save(Reservation newReservation)
 {
     return dataStore.Save(newReservation);
 }
Beispiel #9
0
 private void CheckReservation(Reservation reservation, params Guid[] ignore)
 {
     if (IsOverlappingOthers(reservation, ignore))
     {
         throw new InvalidOperationException("The reservation is overlapping some existing reservations");
     }
 }
Beispiel #10
0
        public Guid AddReservation(Reservation newReservation)
        {
            CheckReservation(newReservation);

            return repository.Save(newReservation);
        }
Beispiel #11
0
 private bool IsOverlappingOthers(Reservation newReservation, params Guid[] ignore)
 {
     return repository.FetchAll()
         .Where(r => !ignore.Contains(r.Key))
         .Any(r =>
         IsBetweenInclusive(newReservation.StartsAt, r.Value.StartsAt, r.Value.EndsAt)
         || IsBetweenInclusive(newReservation.EndsAt, r.Value.StartsAt, r.Value.EndsAt)
         );
 }
Beispiel #12
0
 private bool IsCurrentUserReservationOwner(Reservation reservation)
 {
     Check.Condition(currentUser.Value != null, "Current user is undefined");
     return reservation.RequestedBy.Username == currentUser.Value.Username;
 }
 public void Put(Guid id, Reservation reservation)
 {
     reservationEngine.ChangeReservation(id, reservation);
 }
Beispiel #14
0
        private static string GetComments(Reservation res)
        {
            StringBuilder b = new StringBuilder();
            b.AppendLine(@"<ul>");
            foreach (var comment in res.Comments)
            {
                b.AppendLine(Format.Invariant(@"<li><b>{0}</b> - {1}: {2}</li>",
                    comment.By.FullName, comment.Timestamp.ToShortTimeString(), comment.Says));
            }
            b.AppendLine(@"</ul>");

            return b.ToString();
        }
Beispiel #15
0
 private static string FormatSubject(Reservation res)
 {
     return Format.Invariant("Meeting scheduled for {0} {1}: {2}",
         GetDayName(res.StartsAt), res.StartsAt.ToShortDateString(), res.Title);
 }
Beispiel #16
0
        private static string GetParticipants(Reservation res)
        {
            StringBuilder b = new StringBuilder();
            b.AppendLine(@"<ul>");
            foreach (var participant in res.Participants)
            {
                b.AppendLine(Format.Invariant(@"<li><b>{0}</b> ({1})</li>",
                    participant.FullName, participant.Email));
            }
            b.AppendLine(@"</ul>");

            return b.ToString();
        }