예제 #1
0
        private async Task HandleAsync(LeaseFinalizedEvent @event)
        {
            // Handle lease finalize event - update property status
            //
            var rentalProperty = _context.Property.FirstOrDefault(p => p.Id == @event.RentalPropertyId);

            if (rentalProperty != null)
            {
                RentalStatus status = (RentalStatus)Enum.Parse(typeof(RentalStatus), "rented", true);

                rentalProperty.StatusUpdate(status);

                try
                {
                    await _context.SaveChangesAsync();

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



            //throw new NotImplementedException();
        }
예제 #2
0
        private async Task HandleAsync(LeaseFinalizedEvent @event)
        {
            // Handle lease finalize event - update property status
            //

            //var listing = _context.PropertyListing.FirstOrDefault(l => l.RentalPropertyId == @event.RentalPropertyId);

            //var pId = listing.RentalPropertyId;



            var rentalProperty = _context.RentalProperty.FirstOrDefault(p => p.OriginalId == @event.RentalPropertyId);

            if (rentalProperty != null)
            {
                var listing = _context.PropertyListing.FirstOrDefault(l => l.RentalPropertyId == rentalProperty.Id);



                var applicaton = _context.RentalApplication.FirstOrDefault(a => a.RentalPropertyId == rentalProperty.Id);

                ApplicationStatus appStatus = (ApplicationStatus)Enum.Parse(typeof(ApplicationStatus), "Finalized");

                applicaton.StatusUpdate(applicaton, appStatus);
                ListingStatus status = (ListingStatus)Enum.Parse(typeof(ListingStatus), "rented", true);

                if (listing != null)
                {
                    listing.DeActivate(listing);
                }

                rentalProperty.StatusUpdate(status);

                _context.PropertyListing.Update(listing);
                _context.RentalProperty.Update(rentalProperty);
                _context.RentalApplication.Update(applicaton);

                try
                {
                    await _context.SaveChangesAsync();

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



            //throw new NotImplementedException();
        }
예제 #3
0
        public async Task <Unit> Handle(FinalizeLeaseCommand request, CancellationToken cancellationToken)
        {
            var lease = _context.Lease.FirstOrDefault(l => l.Id == request.LeaseId);

            var rentalproeprty = _context.RentalProperty.FirstOrDefault(p => p.Id == lease.RentalPropertyId);

            var updated = lease.Finalize(request.LeaseSignDate);

            rentalproeprty.StatusUpdate("Rented");

            _context.RentalProperty.Update(rentalproeprty);

            _context.Lease.Update(updated);

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


                // Send message to MQ
                //
                LeaseFinalizedEvent e = new LeaseFinalizedEvent(Guid.NewGuid(), /*rentalproeprty.ListinglId,*/ rentalproeprty.OriginalId);

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

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

                // Logging
                Log.Information("The lease {LeaseName} been finalized, signed on {SignDate}", lease.LeaseTitle, updated.LeaseSignDate);
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error while finalizign the lease {LeaseTile}.", lease.LeaseTitle);
            }

            return(await Unit.Task);

            //throw new NotImplementedException();
        }
예제 #4
0
 private Task HandleAsync(LeaseFinalizedEvent leaseFinalizedEvent)
 {
     throw new NotImplementedException();
 }
예제 #5
0
        public async Task <UpdateLeaseAgreementViewModel> Handle(UpdateLeaseCommand request, CancellationToken cancellationToken)
        {
            bool finalize = false;

            var lease = _context.Lease
                        .Include(p => p.RentalProperty)
                        .ThenInclude(p => p.RentalPropertyOwners)
                        .Include(l => l.RentCoverage)
                        .Include(t => t.Tenant).ToList()
                        .FirstOrDefault(l => l.Id == request.Id);

            bool currentStatus = lease.IsActive;

            var coverage = new RentCoverage(request.Water, request.Cablevison, request.Electricity, request.Internet, request.Heat,
                                            request.NaturalGas, request.SewageDisposal, request.SnowRemoval, request.Storage, request.RecreationFacility,
                                            request.GarbageCollection, request.RecycleServices, request.KitchenScrapCollection, request.Laundry,
                                            /*request.FreeLaundry, */ request.Regigerator, request.Dishwasher, request.StoveOven, request.WindowCovering,
                                            request.Furniture, request.Carpets, request.ParkingStall, request.Other);
            //lease.RentCoverage;


            var property = lease.RentalProperty;
            var tenants  = lease.Tenant;

            var owners = lease.RentalProperty.RentalPropertyOwners;

            bool tmpActiveStatus;

            if (request.Type == 1)
            {
                tmpActiveStatus = false; // make renewd lease agreement to have a finalizing option
            }
            else
            {
                tmpActiveStatus = request.IsActive;
            }

            lease.Update(request.Type, request.LeaseTitle, request.LeaseDesc, request.LeaseStartDate, request.LeaseEndDate,
                         request.Term, request.RentFrequency, request.RentAmount, request.RentDueOn, request.DamageDepositAmount, request.PetDepositAmount,
                         request.LeaseSignDate, tmpActiveStatus, request.IsAddendumAvailable, request.EndLeaseCode, request.RenewTerm,
                         request.Notes, coverage);

            // Find out if this is for fianlization of the lease agreement

            //bool currentStatus = lease.IsActive;

            bool futureStatus = request.IsActive;

            if (currentStatus == false && futureStatus == true)
            {
                // Finalizing operation with SignDate

                property.StatusUpdate("Rented");

                _context.RentalProperty.Update(property);

                lease.Finalize(request.LeaseSignDate);

                finalize = true;
            }



            _context.Lease.Update(lease);

            var updatedLease = new UpdateLeaseAgreementViewModel();

            updatedLease.Type                = request.Type;
            updatedLease.LeaseTitle          = request.LeaseTitle;
            updatedLease.LeaseDesc           = request.LeaseDesc;
            updatedLease.LeaseStartDate      = request.LeaseStartDate;
            updatedLease.Id                  = request.Id;
            updatedLease.LeaseEndDate        = request.LeaseEndDate;
            updatedLease.RentAmount          = request.RentAmount;
            updatedLease.RentDueOn           = request.RentDueOn;
            updatedLease.RentFrequency       = request.RentFrequency;
            updatedLease.DamageDepositAmount = request.DamageDepositAmount;
            updatedLease.PetDepositAmount    = request.PetDepositAmount;
            updatedLease.Term                = request.Term;
            updatedLease.RenewTerm           = request.RenewTerm;
            updatedLease.LeaseSignDate       = request.LeaseSignDate;
            updatedLease.IsActive            = request.IsActive;
            updatedLease.IsAddendumAvailable = request.IsAddendumAvailable;
            updatedLease.EndLeaseCode        = request.EndLeaseCode;
            updatedLease.Notes               = request.Notes;
            updatedLease.Created             = DateTime.Now;
            updatedLease.Modified            = DateTime.Now;
            updatedLease.rentCoverage        = coverage;
            updatedLease.rentalProperty      = lease.RentalProperty;
            updatedLease.RentalPropertyId    = lease.RentalPropertyId;
            updatedLease.Tenant              = tenants.ToList();
            updatedLease.propertyOwners      = owners.ToList();

            try
            {
                await _context.SaveChangesAsync();

                // Send message to message queue if it is finalizing opeatrion

                if (finalize)
                {
                    LeaseFinalizedEvent e = new LeaseFinalizedEvent(Guid.NewGuid(), /*rentalproeprty.ListinglId,*/ property.OriginalId);

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

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

                    // Logging
                    Log.Information("The lease {LeaseName} been finalized, signed on {SignDate}", lease.LeaseTitle, lease.LeaseSignDate);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //throw new NotImplementedException();

            return(updatedLease);
        }