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

            var viewing = new Models.Viewing
            {
                Date   = command.Date,
                Time   = command.Time,
                UserId = command.BuyerUserId,
            };

            if (property.Viewings == null)
            {
                property.Viewings = new List <Models.Viewing>();
            }

            property.Viewings.Add(viewing);

            _context.SaveChanges();
        }
        public bool Handle(BookViewingCommand command)
        {
            if (_context.Viewing.Any(x => x.BuyerId.Equals(command.BuyerId) &&
                                     x.PropertyId.Equals(command.PropertyId) &&
                                     DbFunctions.TruncateTime(x.ViewAt) ==
                                     DbFunctions.TruncateTime(command.ViewingDate)))
            {
                return(false);
            }

            var vewing = new Models.Viewing
            {
                ViewAt     = command.ViewingDate + command.ViewingTime,
                BuyerId    = command.BuyerId,
                PropertyId = command.PropertyId
            };

            _context.Viewing.Add(vewing);

            _context.SaveChanges();

            return(true);
        }