Exemplo n.º 1
0
 public AvailabilityModule(IRavenSessionProvider store)
 {
     using (var session = store.GetSession())
     {
         Get["/"] = parameters => GetDiaryForWeek(session, DateTime.Now.Date);
         Get["/month"] = parameters => GetDiaryForMonth(session, DateTime.Now);
         Get["/day"] = parameters => GetDiaryForDay(session, DateTime.Now.Date);
         Get[@"/day/(?<day>[\d]{1,2})/(?<month>[\d]{1,2})/(?<year>[\d]{1,4})/"] =
             parameters => GetDiaryForDay(session, new DateTime(parameters.year, parameters.month, parameters.day));
         Get["/month/{month}/{year}"] = parameters => GetDiaryForMonth(session, new DateTime(parameters.year, parameters.month, 1));
         Get[@"/(?<day>[\d]{1,2})/(?<month>[\d]{1,2})/(?<year>[\d]{1,4})/"] =
             parameters => GetDiaryForWeek(session, new DateTime(parameters.year, parameters.month, parameters.day));
     }
 }
Exemplo n.º 2
0
        public NancyModule BuildModule(NancyModule module, NancyContext context)
        {
            CreateNegotiationContext(module, context);
            module.Context            = context;
            module.Response           = this.responseFormatterFactory.Create(context);
            module.ViewFactory        = this.viewFactory;
            module.ModelBinderLocator = this.modelBinderLocator;
            module.ValidatorLocator   = this.validatorLocator;

            context.Items.Add(Conventions.RavenSession, ravenSessionProvider.GetSession());
            module.After.AddItemToStartOfPipeline(ctx =>
            {
                var session = ctx.Items [Conventions.RavenSession] as IDocumentSession;
                session.SaveChanges();
                session.Dispose();
            }
                                                  );
            return(module);
        }
Exemplo n.º 3
0
 public LookupModule(IRavenSessionProvider store)
 {
     using (var session = store.GetSession())
     {
         Get["/lookup/rates/for/rooms/{roomId}"] = parameters =>
                                                 {
                                                     var room = session.Load<Room>("rooms/" + parameters.roomId.ToString());
                                                     if (room == null)
                                                         return new NotFoundResponse();
                                                     return Response.AsJson(((Room)room).Rates);
                                                 };
         Get[@"/lookup/occupancy/for/day/{day}/{month}/{year}/"] = parameters =>
         {
             var dateString = string.Format("{0} {1} {2}",
                 parameters.day, parameters.month, parameters.year);
             var date = DateTime.Parse(dateString);
             return View[new DayOccupancyModel
                                 {
                                     CurrentBookings = DiaryManager.DayCheck(date, session),
                                     AllRooms = Room.All(session),
                                     Date = date
                                 }];
         };
         Post["/lookup/contact/from/phoneNumber"] = parameters =>
         {
             var model = this.Bind<ContactLookupForm>();
             var contact = Contact.GetByPhone(model.PhoneNumber, session);
             if (contact == null)
                 return Response.AsJson<Contact>(null);
             return Response.AsJson(new ContactModel
                                        {
                                            Id = contact.Id,
                                            EmailAddress = contact.EmailAddress,
                                            MainContactName = contact.MainContactName,
                                            Name = contact.Name,
                                            PhoneNumber = model.PhoneNumber,
                                            CurrentOwings = string.Format("{0:£0.00}", contact.CurrentlyOverdue(session))
                                        });
         };
     }
 }
Exemplo n.º 4
0
        public NancyModule BuildModule(NancyModule module, NancyContext context)
        {
            module.Context            = context;
            module.Response           = this.responseFormatterFactory.Create(context);
            module.ViewFactory        = this.viewFactory;
            module.ModelBinderLocator = this.modelBinderLocator;
            module.ValidatorLocator   = this.validatorLocator;

            if (module is DinnerParty.Modules.PersistModule)
            {
                context.Items.Add("RavenSession", _ravenSessionProvider.GetSession());
                //module.After.AddItemToStartOfPipeline(ctx =>
                //{
                //    var session =
                //        ctx.Items["RavenSession"] as IDocumentSession;
                //    session.SaveChanges();
                //    session.Dispose();
                //});
            }

            return(module);
        }
Exemplo n.º 5
0
        public BookingModule(IRavenSessionProvider store)
        {
            using (var session = store.GetSession())
            {
                Get[@"/booking"] = parameters =>
                {
                    if (ValidBookingQueryString())
                        return new NotFoundResponse();
                    var date = new DateTime(Request.Query.year, Request.Query.month,
                                            Request.Query.day);
                    string productName = Request.Query.product;
                    var product = session.Query<Product>()
                                               .FirstOrDefault(x => x.Name == productName.ToSpacedString());
                    if (product == null)
                        return new NotFoundResponse();
                    var rooms = product.RoomsToPickFrom(session);
                    if (product.SelectedForm == Product.FormType.Standard)
                        return View[new StandardFormBookingModel
                        {
                            ProductFriendlyName = product.Name,
                            BookingHint = product.BookingHint,
                            Date = date,
                            CurrentBookings = DiaryManager.DayCheck(date, session),
                            Rooms = rooms,
                            AllRooms = Room.All(session),
                            AvailableAdditionalEquipment = AdditionalEquipment.All(session)
                        }];
                    if (product.SelectedForm == Product.FormType.Extended)
                        return View[new ExtendedFormBookingModel
                        {
                            ProductFriendlyName = product.Name,
                            BookingHint = product.BookingHint,
                            Date = date,
                            CurrentBookings = DiaryManager.DayCheck(date, session),
                            Rooms = rooms,
                            AllRooms = Room.All(session),
                            AvailableAdditionalEquipment = AdditionalEquipment.All(session)
                        }];
                    if (product.SelectedForm == Product.FormType.Abbreviated)
                        return View[new AbbreviatedFormBookingModel
                        {
                            ProductFriendlyName = product.Name,
                            BookingHint = product.BookingHint,
                            Date = date,
                            CurrentBookings = DiaryManager.DayCheck(date, session),
                            Rooms = rooms,
                            AllRooms = Room.All(session)
                        }];
                    return new NotFoundResponse();

                };
                Get[@"/booking/{bookingId}"] = parameters =>
                {
                    var booking =
                        Booking.Get("booking/" + parameters.bookingId,
                                    session) as Booking;
                    if (booking == null)
                        return new NotFoundResponse();
                    if (booking.Product.SelectedForm == Product.FormType.Standard)
                        return View[new StandardFormBookingModel(booking)
                        {
                            CurrentBookings = DiaryManager.DayCheck(booking.Date, session),
                            Rooms = booking.Product.RoomsToPickFrom(session),
                            AllRooms = Room.All(session),
                            AvailableAdditionalEquipment = AdditionalEquipment.All(session)
                        }];
                    if (booking.Product.SelectedForm == Product.FormType.Extended)
                        return View[new ExtendedFormBookingModel(booking)
                        {
                            CurrentBookings = DiaryManager.DayCheck(booking.Date, session),
                            Rooms = booking.Product.RoomsToPickFrom(session),
                            AllRooms = Room.All(session),
                            AvailableAdditionalEquipment = AdditionalEquipment.All(session)
                        }];
                    if (booking.Product.SelectedForm == Product.FormType.Abbreviated)
                        return View[new AbbreviatedFormBookingModel(booking)
                        {
                            CurrentBookings = DiaryManager.DayCheck(booking.Date, session),
                            Rooms = booking.Product.RoomsToPickFrom(session),
                            AllRooms = Room.All(session)
                        }];
                    return new NotFoundResponse();
                };
                Get[@"/booking/{bookingId}/NoShow"] = parameters =>
                {
                    var booking =
                           Booking.Get("booking/" + parameters.bookingId,
                                       session) as Booking;
                    if (booking == null)
                        return new NotFoundResponse();
                    booking.NoShow();
                    booking.Save(session);
                    return true;
                };
                Get[@"/booking/{bookingId}/CheckIn"] = parameters =>
                {
                    var booking =
                           Booking.Get("booking/" + parameters.bookingId,
                                       session) as Booking;
                    if (booking == null)
                        return new NotFoundResponse();
                    booking.CheckIn();
                    booking.Save(session);
                    return true;
                };

                Post[@"/booking/{bookingId}/cancel"] = parameters =>
                {
                    var booking =
                           Booking.Get("booking/" + parameters.bookingId,
                                       session) as Booking;
                    if (booking == null)
                        return new NotFoundResponse();
                    var model = this.Bind<CancellationModel>();
                    booking.Cancel(model.CancellationType, model.Reason, DateTime.Now);
                    booking.Save(session);
                    return true;
                };
                Post[@"/booking"] = parameters => SaveBooking(session);
                Post[@"/booking/{bookingId}"] = parameters => SaveBooking(session);
            }
        }