public ActionResult BookViewing(BookViewingCommand bookViewingCommand)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var handler = new BookViewingCommandHandler(_context);

                    bookViewingCommand.BuyerId = User.Identity.GetUserId();

                    if (!handler.Handle(bookViewingCommand))
                    {
                        ModelState.AddModelError("ViewingDate", @"You can book only 1 viewing per day on this property!");
                        var builder   = new AvailableViewingsViewModelBuilder(_context);
                        var viewModel = builder.Build(bookViewingCommand.PropertyId, bookViewingCommand.ViewingDate);
                        viewModel.ViewingTime = bookViewingCommand.ViewingTime;
                        return(View(viewModel));
                    }

                    return(RedirectToAction("Index", "Property"));
                }
                catch (Exception e)
                {
                    return(View("Error", new HandleErrorInfo(e, GetType().Name, MethodBase.GetCurrentMethod().Name)));
                }
            }
            return(View());
        }
예제 #2
0
 public void SetUp()
 {
     _context = Substitute.For<IOrangeBricksContext>();
     _properties = Substitute.For<IDbSet<Models.Property>>();
     _context.Properties.Returns(_properties);
     _handler = new BookViewingCommandHandler(_context);
 }
예제 #3
0
        public ActionResult BookViewing(BookViewingCommand command)
        {
            var handler = new BookViewingCommandHandler(_context);

            handler.Handle(command);

            return(RedirectToAction("Index"));
        }
        public ActionResult BookViewing(BookViewingCommand command)
        {
            command.BuyerId = this.HttpContext.User.Identity.GetUserId();
            var handler = new BookViewingCommandHandler(_uow);

            handler.Handle(command);
            return(RedirectToAction("Index"));
        }
예제 #5
0
        public ActionResult BookViewing(BookViewingCommand command)
        {
            BookViewingCommandHandler handler = new BookViewingCommandHandler(_context);
            string buyerId = User.Identity.GetUserId();

            handler.Handle(command, buyerId);

            return(RedirectToAction("Index"));
        }
        public ActionResult BookViewing(BookViewingCommand command)
        {
            var handler = new BookViewingCommandHandler(_context);

            command.userId = User.Identity.GetUserId();

            handler.Handle(command);

            return(RedirectToAction("Index", "Property"));
        }
        public ActionResult BookViewing(BookViewingCommand command)
        {
            var handler = new BookViewingCommandHandler(_context);

            // Add the user id of the buyer making the offer.
            command.UserId = User.Identity.GetUserId();

            handler.Handle(command);

            return(RedirectToAction("Index"));
        }
예제 #8
0
        public ActionResult BookViewing(BookViewingCommand command)
        {
            if (ModelState.IsValid)
            {
                var handler = new BookViewingCommandHandler(_context);

                command.BuyerUserId = User.Identity.GetUserId();

                handler.Handle(command);
            }
            return(RedirectToAction("Index"));
        }
        public void When_User_Books_Viewing()
        {
            context = Substitute.For <IOrangeBricksContext>();
            context.Properties.Find(1).Returns(new Models.Property {
                Id = 1
            });
            context.Viewings.Returns(Substitute.For <IDbSet <Models.Viewing> >());
            BookViewingCommandHandler handler = new BookViewingCommandHandler(this.context);
            BookViewingCommand        command = new BookViewingCommand
            {
                PropertyId  = 1,
                UserId      = "test",
                ViewingTime = new DateTime(2017, 01, 03, 10, 10, 0)
            };

            handler.Handle(command);
        }
예제 #10
0
        public ActionResult Book(BookViewingViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Book(viewModel.PropertyId));
            }

            var command = new BookViewingCommand
            {
                Appointment = viewModel.Appointment,
                PropertyId  = viewModel.PropertyId,
                BuyerUserId = User.Identity.GetUserId()
            };

            var handler = new BookViewingCommandHandler(_context);

            handler.Handle(command);

            return(RedirectToAction("Index", "Property"));
        }
 public void SetUp()
 {
     _context = Substitute.For <IOrangeBricksContext>();
     _context.Viewings.Returns(Substitute.For <IDbSet <Viewing> >());
     _handler = new BookViewingCommandHandler(_context);
 }