コード例 #1
0
        /// <summary>
        /// Save notification template
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveNotificationTemplate(NotificationTemplateManageModel model)
        {
            ResponseModel response;
            var           notificationTemplate = GetById(model.Id);

            if (notificationTemplate != null)
            {
                notificationTemplate.Name    = model.Name;
                notificationTemplate.Subject = model.Subject;
                notificationTemplate.Body    = model.Body;
                notificationTemplate.Module  = model.Module;
                response = Update(notificationTemplate);

                return(response.SetMessage(response.Success
                    ? T("NotificationTemplate_Message_UpdateSuccessfully")
                    : T("NotificationTemplate_Message_UpdateFailure")));
            }
            Mapper.CreateMap <NotificationTemplateManageModel, NotificationTemplate>();
            notificationTemplate = Mapper.Map <NotificationTemplateManageModel, NotificationTemplate>(model);

            response = Insert(notificationTemplate);
            return(response.SetMessage(response.Success
                ? T("NotificationTemplate_Message_CreateSuccessfully")
                : T("NotificationTemplate_Message_CreateFailure")));
        }
コード例 #2
0
        /// <summary>
        /// Update notification template data
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateNotificationTemplateData(XEditableModel model)
        {
            var item = GetById(model.Pk);

            if (item != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(NotificationTemplateManageModel))
                    .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase));
                if (property != null)
                {
                    object value = model.Value.ToType(property, WorkContext.CurrentTimezone);

                    #region Validate

                    var manageModel = new NotificationTemplateManageModel(item);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

                    if (validationResults.Any())
                    {
                        return(new ResponseModel
                        {
                            Success = false,
                            Message = validationResults.BuildValidationMessages()
                        });
                    }

                    #endregion

                    item.SetProperty(model.Name, value);

                    var response = Update(item);
                    return(response.SetMessage(response.Success
                        ? T("NotificationTemplateMessage_UpdateNotificationTemplateInfoSuccessfully")
                        : T("NotificationTemplate_Message_UpdateNotificationTemplateInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("NotificationTemplate_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("NotificationTemplate_Message_ObjectNotFound")
            });
        }
コード例 #3
0
        /// <summary>
        /// Save contact group, notification template and notification send time
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveNotificationConfiguration(NotificationConfigurationSetupModel model)
        {
            var notification = GetById(model.Id);

            if (notification != null)
            {
                // Save contact group
                if (!string.IsNullOrEmpty(model.ContactGroupName))
                {
                    var contactGroup = new ContactGroupManageModel
                    {
                        Name    = model.ContactGroupName,
                        Queries = notification.ContactQueries
                    };

                    _contactGroupService.SaveContactGroup(contactGroup);
                }

                // Save notification template
                if (!string.IsNullOrEmpty(model.NotificationTemplateName))
                {
                    var notificationTemplateManageModel = new NotificationTemplateManageModel
                    {
                        Name              = model.ContactGroupName,
                        Body              = notification.NotificationBody,
                        Subject           = notification.NotificationSubject,
                        Module            = notification.Module,
                        IsDefaultTemplate = false
                    };

                    _notificationTemplateService.SaveNotificationTemplate(notificationTemplateManageModel);
                }

                // Save notification send time and active record
                notification.SendTime = model.SendTime.HasValue ? model.SendTime : DateTime.UtcNow;
                notification.Active   = true;

                var response = Update(notification);

                return(response.Success
                    ? response.SetMessage(T("Notification_Message_SavingNotificationConfigrationSuccessfully"))
                    : response.SetMessage(T("Notification_Message_SavingNotificationConfigrationFailure")));
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("Notification_Message_ObjectNotFound")
            });
        }
コード例 #4
0
        public ActionResult Edit(NotificationTemplateManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _notificationTemplateService.SaveNotificationTemplate(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    switch (submit)
                    {
                    case SubmitType.Save:
                        return(RedirectToAction("Index"));

                    case SubmitType.SaveAndContinueEdit:
                        return(RedirectToAction("Edit", new { id = model.Id }));
                    }
                }
            }
            return(View(model));
        }