Exemplo n.º 1
0
        public async Task <PropertyListingListViewModel> Handle(CreatePropertyListingCommand request, CancellationToken cancellationToken)
        {
            var contact = new ListingContact(request.ContactName, request.ContactTel,
                                             request.ContactEmail, request.ContactSMS, request.ContactOthers);

            //var listedProperty = _context.RentalProperty.FirstOrDefault(p => p.Id == request.RentalPropertyId);

            var listing = new PropertyListing(request.Title, request.ListingDesc, contact, request.RentalPropertyId, false,
                                              request.MonthlyRent, request.Notes,
                                              DateTime.Now, DateTime.Now);

            var listingProeprty = _context.RentalProperty.FirstOrDefault(p => p.Id == request.RentalPropertyId);

            await _context.AddAsync(listing);

            var addedListing = new PropertyListingListViewModel();


            addedListing.Title             = request.Title;
            addedListing.ListingDesc       = request.ListingDesc;
            addedListing.MonthlyRent       = request.MonthlyRent;
            addedListing.ListingNote       = request.Notes;
            addedListing.IsActive          = false; // this represents the status of listing: published or not
            addedListing.PropertyName      = listingProeprty.PropertyName;
            addedListing.PropertyType      = listingProeprty.PropertyType;
            addedListing.PropertyBuildYear = listingProeprty.PropertyBuildYear;
            addedListing.IsShared          = listingProeprty.IsShared;
            addedListing.IsBasementSuite   = listingProeprty.IsBasementSuite;
            addedListing.Created           = DateTime.Now;
            addedListing.Updated           = DateTime.Now;

            try
            {
                await _context.SaveChangesAsync();

                // Send message to message queue

                addedListing.Id = listing.Id;
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(addedListing);

            //throw new NotImplementedException();
        }
Exemplo n.º 2
0
        private async Task HandleAsync(PropertyCreatedEvent @event)
        {
            //var p = _context.RentalProperty.FirstOrDefault(r => r.Id == 2); // Test code

            var ownerAddress = new OwnerAddress(@event.OwnerStreetNum, @event.OwnerCity, @event.OwnerStateProvince, @event.OwnerCountry, @event.OwnerZipPostCode);

            var owner = new RentalPropertyOwner(@event.OwnerId, @event.OwnerFirstName, @event.OwnerLastName, @event.OwnerContactEmail, @event.OwnerContactTel, @event.OwnerContactOther, ownerAddress, DateTime.Now, DateTime.Now);

            var owners = new List <RentalPropertyOwner>();

            owners.Add(owner);

            await _context.AddAsync(owner);

            var address = new Address(
                @event.StreetNum, @event.City, @event.StateProvince, @event.Country, @event.ZipPostCode);

            int geoId = 0;

            geoId = getGeoId(@event.City);

            var property = new RentalProperty(
                @event.PropertyId, @event.PropertyName, @event.Type, @event.PropertyManagerUserName, @event.PropertyBuildYear,
                @event.IsShared, @event.IsBasementSuite, @event.NumberOfBedrooms, @event.NumberOfBathrooms,
                @event.NumberOfLayers, @event.NumberOfParking, @event.TotalLivingArea, "", DateTime.Now,
                DateTime.Now, address, geoId, owners);


            await _context.AddAsync(property);

            try
            {
                await _context.SaveChangesAsync();

                Log.Information("Message  {MessageType} with Id {MessageId} has been handled successfully", @event.MessageType, @event.MessageId);
            }
            catch (Exception ex)
            {
                //throw ex;
                //string messageId = messageObject.Property("MessageId") != null ? messageObject.Property("MessageId").Value<string>() : "[unknown]";
                Log.Error(ex, "Error while handling {MessageType} message with id {MessageId}.", @event.MessageType, @event.MessageId);
            }

            //throw new NotImplementedException();

            //Log.Information("Message  {MessageType} with Id {MessageId} has been handled successfully", @event.MessageType, @event.MessageId);

            //var msgDetails = new MessageDetails();

            //msgDetails.PrincicipalId = @event.PropertyId;
            //msgDetails.PrincipalType = "Property";
            //msgDetails.PrincipalNameDesc = @event.PropertyName;
            //msgDetails.OperationType = "Create";

            //var details = msgDetails.ToBsonDocument();

            //var msg = new Message(@event.MessageId, "Asset Management", details, "asset_created", "asset_created.*", "Subscription", DateTime.Now);

            //var messageLoggingService = new MessageLoggingService();

            //await messageLoggingService.LogMessage(msg);
        }
Exemplo n.º 3
0
        public async Task <bool> Handle(CreateRentalApplicationCommandV2 request, CancellationToken cancellationToken)
        {
            //var applicant = new RentalApplicant(request.FirstName, request.LastName, request.ContactTel, request.ContactEmail,
            //    request.ContactSms, request.ContactOthers, request.AnnualIncome, request.NumberOfOccupant, request.WithChildren, request.Status,
            //    request.EmpoyedStatus, request.CreditRating,"equifax", request.ReasonToMove, DateTime.Now, DateTime.Now);

            //var coApplicant =

            List <CoApplicant>    CoApplicantList = new List <CoApplicant>();
            List <ApplicantChild> ChildList       = new List <ApplicantChild>();

            List <RentalReference> ReferennceList = new List <RentalReference>();

            foreach (var coApp in request.CoApplicants)
            {
                CoApplicantList.Add(coApp);
            }

            foreach (var child in request.ApplicantChildren)
            {
                ChildList.Add(child);
            }

            foreach (var reference in request.RentalReference)
            {
                ReferennceList.Add(reference);
            }

            var applicant = new RentalApplicant(request.FirstName, request.LastName, request.ContactTel, request.ContactEmail,
                                                request.ContactSms, request.ContactOthers, request.AnnualIncome, request.NumberOfOccupant, request.WithChildren, request.Status,
                                                request.CreditRating, request.CreditSource, request.EmpoyedStatus, request.RentalApplicationId, request.ReasonToMove,
                                                request.WithCoApplicant, request.WithPets, request.IsSmoking, CoApplicantList, ReferennceList, ChildList, DateTime.Now, DateTime.Now);



            await _context.AddAsync(applicant);

            var application = new RentalApplication(request.RentalPropertyId, applicant, request.AppStatus, /*request.NotificaitonType,*/ DateTime.Now, DateTime.Now);

            await _context.AddAsync(application);

            application.AddApplicant(applicant);

            try
            {
                await _context.SaveChangesAsync(); // commented out for testing only

                Log.Information("New Applicatn from {ApplicantName} with Id {ApplicantId} has been created successfully", request.FirstName + " " + request.LastName, applicant.Id);

                // Sending notification??? by sending integration message to RabbitMQ for notification service to pickup and send notificaiotn

                string recipient = "";
                string subject   = "Rental Applicaiton Received";
                //string body = "Your application has been successfully submitted!"; // for testing purpose, To be improved
                //string bodyContent =
                //    "@Dear {name}: " +
                //    "Your application for teancy has been recieved." +
                //    "Please prepare to provide required reference materials for the screening process." +
                //    "Thanks." +
                //    "Property Manager";

                //string body = string.Format(bodyContent, request.FirstName + " " + request.LastName);
                string body = "";

                string service = "Marketing Service";



                switch (request.NotificationType)
                {
                case 1:
                    body      = "Dear " + request.FirstName + ": your application has been received. Best regards.";
                    recipient = request.ContactEmail;
                    break;

                case 2:
                    body      = "Dear " + request.FirstName + ": your application has been received. Best regards.";
                    recipient = request.ContactTel;
                    //if (request.ContactSms != null)
                    //{
                    //    recipient = request.ContactSms;
                    //}
                    //else
                    //{
                    //    // throw errror
                    //    recipient = request.ContactTel;
                    //}
                    break;

                default:
                    break;
                }

                //EmailNotificationEvent e = new EmailNotificationEvent(new Guid(), recipients, request.NotificaitonType, subject, body, service, DateTime.Now);

                NotificationEvent e = new NotificationEvent(new Guid(), recipient, request.NotificationType, subject, body, service, DateTime.Now);

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

                    Log.Information("Rental application submissin from  {Applicant} has been sent successfully from {service}", request.FirstName + " " + request.LastName, service);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error while creating  new applicant for {ApplicantName}", request.FirstName + request.LastName);
            }


            return(true);

            //throw new NotImplementedException();
        }