public async Task DeleteMailTemplate()
        {
            var template = await _mailTemplateHelper.FetchAsync("TEMPLATE1");

            var deleted = await _mailTemplateRepository.DeleteAsync(new List <int> {
                template.ID
            });

            Assert.IsTrue(deleted);
        }
Example #2
0
        private async Task MailTemplatesList_ListAction(ComponentActionEventArgs e)
        {
            if (BtnDeleteSelected && wim.ChangedSearchGridItem != null)
            {
                var mailTemplateIDs = new List <int>();

                foreach (var item in wim.ChangedSearchGridItem)
                {
                    var mailTemplate = item as Data.MailTemplateList;
                    mailTemplateIDs.Add(mailTemplate.ID);
                }

                var isSuccess = await _mailTemplateRepository.DeleteAsync(mailTemplateIDs);

                if (!isSuccess)
                {
                    wim.Notification.AddError("Failed to delete the selected templates.");
                }

                var keyValues = new List <KeyValue>();

                Context.Response.Redirect(wim.GetUrl(keyValues.ToArray()));
            }

            if (BtnPublish && await CanSaveAsync())
            {
                var result = await _mailTemplateListRepository.FetchSingleByIdentifierAsync(Identifier);

                if (result != null && result.ID != Implement.ID)
                {
                    await Notification.InsertOneAsync("Wim.Module.MailTemplate", $"Identifier {Identifier} is already in use.");
                }

                if (await _mailTemplateRepository.PublishAsync(Implement, wim.CurrentApplicationUser.ID, wim.CurrentApplicationUser.Displayname, wim.CurrentApplicationUser.Email))
                {
                    wim.CurrentVisitor.Data.Apply("wim.note", "Template is published", null);
                    await wim.CurrentVisitor.SaveAsync();

                    Response.Redirect(wim.GetUrl(new KeyValue[] {
                        new KeyValue {
                            Key = "list", Value = wim.CurrentList.ID
                        },
                        new KeyValue {
                            Key = "item", Value = Implement.ID
                        }
                    }));
                }
            }

            if (BtnRevert && await _mailTemplateRepository.RevertAsync(Implement, wim.CurrentApplicationUser.ID, wim.CurrentApplicationUser.Displayname, wim.CurrentApplicationUser.Email))
            {
                wim.Notification.AddNotificationAlert($"Template has been reverted to the published version", true);

                Response.Redirect(wim.GetUrl(new KeyValue[] {
                    new KeyValue {
                        Key = "list", Value = wim.CurrentList.ID
                    },
                    new KeyValue {
                        Key = "item", Value = Implement.ID
                    }
                }));
            }
        }