public void Handle(ContactAgentCommand command)
        {
            var property = this._context.Properties.Find(command.PropertyId);

            var propertyViewing = new PropertyViewing
            {
                BuyerName    = command.BuyerName,
                BuyerUserId  = command.BuyerUserId,
                BuyerEmail   = command.Email,
                BuyerPhone   = command.Phone,
                BuyerMessage = command.Message,
                Status       = PropertyViewingStatus.Pending,
                //TODO: Time needs to stored in UTC format and converted to local time based on the user's time zone info
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now
            };

            if (property.PropertyViewings == null)
            {
                property.PropertyViewings = new List <PropertyViewing>();
            }

            property.PropertyViewings.Add(propertyViewing);

            this._context.SaveChanges();
        }
Ejemplo n.º 2
0
        public ActionResult ContactAgent(ContactAgentCommand command)
        {
            var handler = new ContactAgentCommandHandler(this._context);

            command.BuyerUserId = this.User.Identity.GetUserId();
            handler.Handle(command);

            this.TempData["SuccessMessage"] = "We will contact you very shortly to schedule your booking appointment";
            return(this.RedirectToAction("ContactAgent"));
        }
Ejemplo n.º 3
0
        public void HandleShouldAddPropertyViewingForCorrectBuyer()
        {
            // Arrange
            const string buyerUserId = "12345";
            var          command     = new ContactAgentCommand {
                PropertyId = 1, BuyerUserId = buyerUserId
            };

            var property = new Models.Property
            {
                Id          = 1,
                Description = "Test Property"
            };

            this._properties.Find(1).Returns(property);

            // Act
            this._handler.Handle(command);

            // Assert
            Assert.IsTrue(property.PropertyViewings.First().BuyerUserId == buyerUserId);
        }
Ejemplo n.º 4
0
        public void HandleShouldAddPropertyViewing()
        {
            // Arrange
            var command = new ContactAgentCommand {
                PropertyId = 1
            };

            var property = new Models.Property
            {
                Id          = 1,
                Description = "Test Property"
            };

            this._properties.Find(1).Returns(property);

            // Act
            this._handler.Handle(command);

            // Assert
            this._context.Properties.Received(1).Find(1);
            this._context.Received(1).SaveChanges();
            Assert.IsTrue(property.PropertyViewings.Count == 1);
        }