public void Handle(RequestViewingCommand command)
        {
            var      property        = _context.Properties.Find(command.PropertyId);
            DateTime viewingDateTime = default(DateTime);

            DateTime.TryParseExact(string.Format("{0} {1}", command.ViewingDate, command.ViewingTime), "dd/MM/yyyy HH:mm",
                                   CultureInfo.InvariantCulture, DateTimeStyles.None, out viewingDateTime);

            var viewing = new Viewing
            {
                RequestDate   = viewingDateTime,
                CreatedAt     = DateTime.Now,
                UpdatedAt     = DateTime.Now,
                RequestUserId = command.RequestedUserId
            };

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

            property.Viewings.Add(viewing);

            _context.SaveChanges();
        }
Beispiel #2
0
        public void Handle(RequestViewingCommand command)
        {
            var property = _context.Properties.FirstOrDefault(o => o.Id == command.PropertyId);

            var viewing = new Viewing
            {
                ViewingAt   = command.ViewingAt,
                Status      = ViewingStatus.Pending,
                CreatedAt   = DateTime.Now,
                UpdatedAt   = DateTime.Now,
                BuyerUserId = command.BuyerUserId
            };

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

            property.Viewings.Add(viewing);

            _context.SaveChanges();
        }