Exemple #1
0
        private static void HandlePropertyChangeNotificationMessage(PropertyChangeNotificationMessage propertyChangeNotificationMessage)
        {
            IRealEstateContext context = new RealEstateContext(ConfigurationManager.ConnectionStrings["RealEstateConnection"].ToString());
            IRealEstatePropertyInterestRepository realEstatePropertyInterestRepository = new RealEstatePropertyInterestRepository(context);
            IRealEstateNotificationRepository     realEstateNotificationRepository     = new RealEstateNotificationRepository(context);
            var propertyInterests = realEstatePropertyInterestRepository.GetRealEstatePropertyInterests(propertyChangeNotificationMessage.PropertyId);

            foreach (var propertyInterest in propertyInterests)
            {
                //Create Notification
                var notification = new RealEstateNotification
                {
                    Message    = "Property Modification. Please check",
                    PropertyId = propertyChangeNotificationMessage.PropertyId,
                    UserId     = propertyInterest.UserId
                };
                realEstateNotificationRepository.CreateRealEstateNotification(notification);

                //Send Email Notification
                MailHelper mailHelper = new MailHelper();
                mailHelper.Recipient = propertyInterest.User.UserName;
                mailHelper.Subject   = "Property Change Notification";
                mailHelper.Sender    = ConfigurationManager.AppSettings["EmailFromAddress"];
                mailHelper.Body      = $"Property - {propertyInterest.Property.PropertyName} is modified. Please check the app for details";
                mailHelper.Send();
            }
        }
        public async Task <RealEstateNotification> CreateRealEstateNotification(RealEstateNotification realEstateNotification)
        {
            realEstateNotification.CreatedDate = DateTime.Now;
            realEstateNotification.IsActive    = true;
            realEstateNotification.IsRead      = false;
            RealEstateContext.RealEstateNotification.Add(realEstateNotification);
            await RealEstateContext.SaveChangesAsync();

            return(realEstateNotification);
        }