public object Post(Reservation reservation) { Check.NotNull(reservation, "reservation"); var id = reservationEngine.AddReservation(reservation); NotificationEmail.Send(reservation); return new { Id = id }; }
public void ChangeReservation(Guid id, Reservation updatedReservation) { CheckOwnership(id); CheckReservation(updatedReservation, id); repository.Save(id, updatedReservation); }
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); }
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); } } }
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; }
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; }
public void Save(Guid id, Reservation updatedReservation) { dataStore.SaveOrUpdate(new KeyValuePair<Guid, object>(id, updatedReservation)); }
public Guid Save(Reservation newReservation) { return dataStore.Save(newReservation); }
private void CheckReservation(Reservation reservation, params Guid[] ignore) { if (IsOverlappingOthers(reservation, ignore)) { throw new InvalidOperationException("The reservation is overlapping some existing reservations"); } }
public Guid AddReservation(Reservation newReservation) { CheckReservation(newReservation); return repository.Save(newReservation); }
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) ); }
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); }
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(); }
private static string FormatSubject(Reservation res) { return Format.Invariant("Meeting scheduled for {0} {1}: {2}", GetDayName(res.StartsAt), res.StartsAt.ToShortDateString(), res.Title); }
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(); }