Exemplo n.º 1
0
        public bool Handle(MakeOfferCommand command)
        {
            var property = _context.Properties.Find(command.PropertyId);

            if (property.Offers != null && property.Offers.Count(o => o.BuyerUserId == command.BuyerUserId) > 0)
            {
                return(false);
            }

            var offer = new Offer
            {
                Amount      = command.Offer,
                Status      = OfferStatus.Pending,
                CreatedAt   = DateTime.Now,
                UpdatedAt   = DateTime.Now,
                BuyerUserId = command.BuyerUserId
            };

            if (property.Offers == null)
            {
                property.Offers = new List <Offer>();
            }

            property.Offers.Add(offer);

            _context.SaveChanges();

            return(true);
        }
        public void Handle(MakeOfferCommand command)
        {
            var property = _context.Properties.Find(command.PropertyId);

            if (property != null)
            {
                var offer = new Offer
                {
                    Amount      = command.Offer,
                    Status      = OfferStatus.Pending,
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now,
                    BuyerUserId = command.BuyerUserId
                };

                if (property.Offers == null)
                {
                    property.Offers = new List <Offer>();
                }

                property.Offers.Add(offer);

                _context.SaveChanges();
            }
        }
        public void Handle(MakeOfferCommand command)
        {
            var user     = HttpContext.Current.User.Identity.GetUserId();
            var property = _context.Properties.Find(command.Property_Id);

            var offer = new Offer
            {
                Amount    = command.Offer,
                Status    = OfferStatus.Pending,
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now,
                userId    = user
            };

            if (property.Offers == null)
            {
                property.Offers = new List <Offer>();
            }

            property.Offers.Add(offer);

            _context.SaveChanges();
        }