Example #1
0
        protected void CreateNotificationtBtn_Click(object sender, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                NotificationType selectedType;
                bool             isTypeValid = Enum.TryParse(this.TypeDropDownList.SelectedItem.Text, out selectedType);

                if (!isTypeValid)
                {
                    this.InvalidTypeCustomValidatior.ErrorMessage = "Invalid notification type!";
                    this.InvalidTypeCustomValidatior.IsValid      = false;
                    return;
                }

                var notificationEventArgs = new NotificationsManagementEventArgs()
                {
                    Content     = this.ContentAjaxHtmlEditor.Content,
                    DateCreated = DateTime.Now,
                    Type        = selectedType
                };

                this.OnNotificationsAddItem?.Invoke(null, notificationEventArgs);

                this.SuccessPanel.Visible            = true;
                this.AddedNotificationIdLiteral.Text = notificationEventArgs.Id.ToString();

                this.ClearFeilds();
            }
        }
        private void View_OnNotificationsUpdateItem(object sender, NotificationsManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(NotificationsManagementEventArgs));
            }

            var notification = this.notificationsServices.GetNotification(e.Id);

            if (notification == null)
            {
                this.View.ModelState.AddModelError(
                    ErrorMessages.MODEL_ERROR_KEY,
                    string.Format(ErrorMessages.MODEL_ERROR_MESSAGE, e.Id));

                return;
            }

            this.View.TryUpdateModel(notification);

            if (this.View.ModelState.IsValid)
            {
                this.notificationsServices.UpdateNotification(e.Id, notification);
            }
        }
        private void View_OnNotificationsDeleteItem(object sender, NotificationsManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(NotificationsManagementEventArgs));
            }

            this.notificationsServices.DeleteNotification(e.Id);
        }
        private void View_OnNotificationsAddItem(object sender, NotificationsManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(NotificationsManagementEventArgs));
            }

            var notification = new Notification()
            {
                Content     = e.Content,
                DateCreated = e.DateCreated,
                Type        = e.Type
            };

            e.Id = this.notificationsServices.AddNotification(notification);
        }