示例#1
0
        private Task HandleAsync(RentalPropertyStatusChangeEvent rentalPropertyStatusChangeEvent)
        {
            //Handling status change for the listed property


            throw new NotImplementedException();
        }
示例#2
0
        private async Task HandleAsync(RentalPropertyStatusChangeEvent e)
        {
            var property = _context.Property
                           .FirstOrDefault(p => p.Id == e.OriginalPropertyId);

            string newStatus = "";

            if (e.CurrentStatus == "Listed")
            {
                newStatus = "Vacant";
            }
            else
            {
                newStatus = e.CurrentStatus;
            }

            //if (e.CurrentStatus == "NotSet")
            //{
            //    newStatus = "UnSet";
            //}


            RentalStatus status = (RentalStatus)Enum.Parse(typeof(RentalStatus), newStatus, true);

            //property.StatusUpdate(property, status); // update method chagned

            if (property != null)
            {
                property.StatusUpdate(status);

                try
                {
                    await _context.SaveChangesAsync();

                    Log.Information("Message  {MessageType} with Id {MessageId} has been handled successfully: Updated property status!", e.MessageType, e.MessageId);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error while publishing {MessageType} message with id {MessageId}. Property status not updated!d", e.MessageType, e.MessageId);
                    throw ex;
                }
            }



            //var owner = _context.PropertyOwner.FirstOrDefault(p => p.Id == 1);

            //throw new NotImplementedException();
        }
示例#3
0
        public async Task <Unit> Handle(PublishPropertyListingCommand request, CancellationToken cancellationToken)
        {
            var listing = _context.PropertyListing
                          .Include(l => l.RentalProperty)
                          .FirstOrDefault(l => l.Id == request.Id);

            listing.Publish(listing);

            // Update rental property status
            //
            string newStatus = "";

            ListingStatus status = (ListingStatus)Enum.Parse(typeof(ListingStatus), newStatus, true);

            listing.RentalProperty.StatusUpdate(status);

            try
            {
                await _context.SaveChangesAsync(); // comment out for testing message sending
            }
            catch (Exception ex)
            {
                throw;
            }
            // Send status chagne message to the message queue so that the Asset service can update the status of the property

            RentalPropertyStatusChangeEvent e = new RentalPropertyStatusChangeEvent(new Guid(), listing.RentalProperty.OriginalId, "Listed");

            try
            {
                await _messagePublisher.PublishMessageAsync(e.MessageType, e, "status_updated");

                Log.Information("Message  {MessageType} with Id {MessageId} has been published successfully", e.MessageType, e.MessageId);
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error while handling {MessageType} message with id {MessageId}.", e.MessageType, e.MessageId);
            }

            return(await Unit.Task);

            //throw new NotImplementedException();
        }
示例#4
0
        /// <summary>
        /// This update listing process only catches published/listed event so that Asset microservice can upate the property status from "UnSet" to "Vacant" or vice verser
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <PropertyListingUpdateViewModel> Handle(UpdatePropertyListingCommand request, CancellationToken cancellationToken)
        {
            var listing = _context.PropertyListing
                          .Include(r => r.RentalProperty)
                          .ThenInclude(p => p.PropertyImg)
                          .FirstOrDefault(i => i.Id == request.Id);
//.ThenInclude(m => m.PropertyImg.ToList())
            var contact = new ListingContact(request.ContactName, request.ContactTel,
                                             request.ContactEmail, request.ContactSMS, request.ContactOthers);

            var allImgs = _context.PropertyImg.ToList(); // Get all property images

            var rentalProperty = listing.RentalProperty;

            var originalStatus = listing.IsActive;

            var updated = listing.Update(listing, request.Title, request.ListingDesc, contact, request.MonthlyRent, request.isActive, request.Note, DateTime.Now);

            _context.PropertyListing.Update(updated);

            var updatedList = new PropertyListingUpdateViewModel();  // need to include all images?

            updatedList.Id = updated.Id;
            updatedList.RentalPropertyId = updated.RentalPropertyId;
            updatedList.Title            = updated.Title;
            updatedList.ListingDesc      = updated.ListingDesc;
            updatedList.MonthlyRent      = updated.MonthlyRent;
            updatedList.Note             = updated.Note;
            updatedList.IsActive         = updated.IsActive;
            updatedList.ContactName      = updated.Contact.ContactName;
            updatedList.ContactEmail     = updated.Contact.ContactEmail;
            updatedList.ContactTel       = updated.Contact.ContactTel;
            updatedList.ContactSMS       = updated.Contact.ContactSMS;
            updatedList.ContactOthers    = updated.Contact.ContactOthers;
            updatedList.Created          = updated.Created;
            updatedList.Modified         = updated.Modified;
            updatedList.Updated          = updated.Modified;

            updatedList.RentalProperty = listing.RentalProperty;
            updatedList.PropertyName   = listing.RentalProperty.PropertyName;
            updatedList.PropertyImgs   = allImgs;

            updatedList.Contact = contact;

            //updatedList.PropertyImgs = allImgs.ToList();

            // Update rental property status

            ListingStatus status;

            if (request.isActive == true)
            {
                status = (ListingStatus)Enum.Parse(typeof(ListingStatus), "Listed");
            }
            else
            {
                status = (ListingStatus)Enum.Parse(typeof(ListingStatus), "NotSet");
            }

            rentalProperty.StatusUpdate(status);

            try
            {
                await _context.SaveChangesAsync();

                // Only send message to the message queue for status change, i.e. isActive from true to false or vice versa
                if (originalStatus != request.isActive)
                {
                    RentalPropertyStatusChangeEvent e = new RentalPropertyStatusChangeEvent(new Guid(), listing.RentalProperty.OriginalId, status.ToString());

                    try
                    {
                        await _messagePublisher.PublishMessageAsync(e.MessageType, e, "status_updated"); // publishing the message

                        Log.Information("Message  {MessageType} with Id {MessageId} has been published successfully: Proeprty status change.", e.MessageType, e.MessageId);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "Error while publishing {MessageType} message with id {MessageId}. Proeprty status change.", e.MessageType, e.MessageId);

                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Information("Error {Message} saving to database!", ex.Message);
                throw ex;
            }

            return(updatedList);

            //throw new NotImplementedException();
        }
示例#5
0
        public async Task <PropertyListingUpdateViewModel> Handle(UpldatePropertyLisitngStatusCommand request, CancellationToken cancellationToken)
        {
            var listing = _context.PropertyListing.FirstOrDefault(l => l.Id == request.Id);

            var updated = listing.StatusUpdate(listing, request.IsActive);


            _context.PropertyListing.Update(updated);

            int origId = 0;

            if (request.RentalPropertyStatus.ToString() != "NotSet")
            {
                var property = _context.RentalProperty.FirstOrDefault(p => p.Id == listing.RentalPropertyId);
                property.ListingStatusUpdate(property, request.RentalPropertyStatus);

                origId = property.OriginalId;

                _context.RentalProperty.Update(property);
            }

            var updatedList = new PropertyListingUpdateViewModel();

            updatedList.Id = updated.Id;
            updatedList.RentalPropertyId = updated.RentalPropertyId;
            updatedList.Title            = updated.Title;
            updatedList.ListingDesc      = updated.ListingDesc;
            updatedList.MonthlyRent      = updated.MonthlyRent;
            updatedList.Note             = updated.Note;
            updatedList.IsActive         = updated.IsActive;
            updatedList.ContactName      = updated.Contact.ContactName;
            updatedList.ContactEmail     = updated.Contact.ContactEmail;
            updatedList.ContactTel       = updated.Contact.ContactTel;
            updatedList.ContactSMS       = updated.Contact.ContactSMS;
            updatedList.ContactOthers    = updated.Contact.ContactOthers;
            updatedList.Created          = updated.Created;
            updatedList.Modified         = updated.Modified;

            updatedList.RentalProperty = listing.RentalProperty;

            //updatedList.Contact = contact;

            try
            {
                await _context.SaveChangesAsync(); // comment out for testing message sending

                if (request.RentalPropertyStatus.ToString() == "Pending" || request.RentalPropertyStatus.ToString() == "Rented")
                {
                    // Send message to queue to update property status in Asset Service
                    //
                    RentalPropertyStatusChangeEvent e = new RentalPropertyStatusChangeEvent(Guid.NewGuid(), origId, request.RentalPropertyStatus.ToString());
                    await _messagePublisher.PublishMessageAsync(e.MessageType, e, "status_updated.*");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(updatedList);

            //throw new NotImplementedException();
        }