internal IValidationResult NotificationRecipient(NotificationRecipient notificationRecipient)
        {
            IValidationResult validationResult = new ValidationResult();

            // Null checks.
            if (notificationRecipient.TwitterHandle == null)
            {
                validationResult.AddError("TwitterHandle.Null", "TwitterHandle cannot be null.");
            }

            if (notificationRecipient.Description == null || notificationRecipient.Description == string.Empty)
            {
                validationResult.AddError("Description.Null", "Description cannot be null or an empty string.");
            }

            // Regex checks.
            if (notificationRecipient.TwitterHandle != null)
            {
                if (!Regex.Match(notificationRecipient.TwitterHandle, "^@(\\w){1,15}$").Success)
                {
                    validationResult.AddError("TwitterHandle.Format", "Invalid twitter handle.");
                }
            }

            // Range checks.
            if (notificationRecipient.AlertIntervalHours < 1 || notificationRecipient.AlertIntervalHours > 168)
            {
                validationResult.AddError("AlertIntervalHours.Range", "AlertIntervalHours is outside of expected ranges. AlertIntervalHours should be between 1 and 168 hours (one week).");
            }

            return validationResult;
        }
 public void UpdateNotificationRecipient(NotificationRecipient notificationRecipient)
 {
     NotificationRecipientOperations.UpdateNotificationRecipient(notificationRecipient);
 }
 public NotificationRecipient CreateNotificationRecipient(NotificationRecipient notificationRecipient)
 {
     return NotificationRecipientOperations.CreateNotificationRecipient(notificationRecipient);
 }
 public NotificationRecipient AddNotificationRecipient(NotificationRecipient notificationRecipient)
 {
     return NotificationRecipientOperations.AddNotificationRecipient(notificationRecipient);
 }
 internal void UpdateNotificationRecipient(NotificationRecipient notificationRecipient)
 {
     notificationRecipient.ObjectState = ObjectState.Modified;
     this.unitOfWork.Repository<NotificationRecipient>().Update(notificationRecipient);
 }
 internal NotificationRecipient CreateNotificationRecipient(NotificationRecipient notificationRecipient)
 {
     notificationRecipient.ObjectState = ObjectState.Added;
     this.unitOfWork.Repository<NotificationRecipient>().Insert(notificationRecipient);
     return notificationRecipient;
 }
 internal NotificationRecipient AddNotificationRecipient(NotificationRecipient notificationRecipient)
 {
     this.unitOfWork.Repository<NotificationRecipient>().Insert(notificationRecipient);
     return notificationRecipient;
 }
 /// <summary>
 /// Updates a notification recipient for a particular account.
 /// </summary>
 /// <param name="notificationRecipient">A partially populated notification recipient object to be updated.</param>
 /// <returns>Returns a validation result object.</returns>
 public IValidationResult UpdateNotificationRecipient(NotificationRecipient notificationRecipient)
 {
     return AccountManager.UpdateNotificationRecipient(notificationRecipient);
 }
        /// <summary>
        /// Updates a notification recipient for a particular account.
        /// </summary>
        /// <param name="notificationRecipient">A partially populated notification recipient object to be updated.</param>
        /// <returns>Returns a validation result object.</returns>
        internal IValidationResult UpdateNotificationRecipient(NotificationRecipient notificationRecipient)
        {
            IValidationResult validationResult = new ValidationResult();

            var existingNotificationRecipient = this.doctrineShipsRepository.GetNotificationRecipient(notificationRecipient.NotificationRecipientId);

            if (existingNotificationRecipient != null)
            {
                if (existingNotificationRecipient.AccountId != notificationRecipient.AccountId)
                {
                    validationResult.AddError("NotificationRecipient.Permission", "The notification recipient being modified does not belong to the requesting account.");
                }
                else
                {
                    // Map the updates to the existing notification recipient.
                    existingNotificationRecipient.AlertIntervalHours = notificationRecipient.AlertIntervalHours;
                    existingNotificationRecipient.ReceivesAlerts = notificationRecipient.ReceivesAlerts;
                    existingNotificationRecipient.ReceivesDailySummary = notificationRecipient.ReceivesDailySummary;

                    // Validate the notification recipient updates.
                    validationResult = this.doctrineShipsValidation.NotificationRecipient(existingNotificationRecipient);
                    if (validationResult.IsValid == true)
                    {
                        // Update the existing record, save and log.
                        this.doctrineShipsRepository.UpdateNotificationRecipient(existingNotificationRecipient);
                        this.doctrineShipsRepository.Save();
                        logger.LogMessage("Notification Recipient '" + existingNotificationRecipient.Description + "' Successfully Updated For Account Id: " + existingNotificationRecipient.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name);
                    }
                }
            }

            return validationResult;
        }
        /// <summary>
        /// <para>Adds a notification recipient for an account.</para>
        /// </summary>
        /// <param name="accountId">The id of the account for which a recipient should be added.</param>
        /// <param name="twitterHandle">The twitter handle for the recipient.</param>
        /// <param name="description">A short description for the recipient.</param>
        /// <returns>Returns a validation result object.</returns>
        internal IValidationResult AddNotificationRecipient(int accountId, string twitterHandle, string description)
        {
            IValidationResult validationResult = new ValidationResult();

            // Populate a new account object.
            NotificationRecipient newNotificationRecipient = new NotificationRecipient();

            // Populate the remaining properties.
            newNotificationRecipient.AccountId = accountId;
            newNotificationRecipient.TwitterHandle = twitterHandle;
            newNotificationRecipient.Description = description;
            newNotificationRecipient.ReceivesDailySummary = true;
            newNotificationRecipient.ReceivesAlerts = true;
            newNotificationRecipient.AlertIntervalHours = 12;
            newNotificationRecipient.Method = NotificationMethod.DirectMessage;
            newNotificationRecipient.LastAlert = DateTime.UtcNow;

            // Validate the new notification recipient.
            validationResult = this.doctrineShipsValidation.NotificationRecipient(newNotificationRecipient);
            if (validationResult.IsValid == true)
            {
                // Add the new notification recipient.
                this.doctrineShipsRepository.CreateNotificationRecipient(newNotificationRecipient);
                this.doctrineShipsRepository.Save();

                // Log the addition.
                logger.LogMessage("Notification Recipient '" + newNotificationRecipient.Description + "' Successfully Added For Account Id: " + newNotificationRecipient.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name);
            }

            return validationResult;
        }
 public IValidationResult NotificationRecipient(NotificationRecipient notificationRecipient)
 {
     return AccountCheck.NotificationRecipient(notificationRecipient);
 }