public void Can_Perform_Delete_View()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ITemplateRepository repository = CreateRepository(provider);

                var template = new Template(ShortStringHelper, "test", "test")
                {
                    Content = "mock-content"
                };
                repository.Save(template);

                // Act
                ITemplate templates = repository.Get("test");
                Assert.That(FileSystems.MvcViewsFileSystem.FileExists("test.cshtml"), Is.True);
                repository.Delete(templates);

                // Assert
                Assert.IsNull(repository.Get("test"));
                Assert.That(FileSystems.MvcViewsFileSystem.FileExists("test.cshtml"), Is.False);
            }
        }
        /// <summary>
        /// Deletes a template by its alias
        /// </summary>
        /// <param name="alias">Alias of the <see cref="ITemplate"/> to delete</param>
        /// <param name="userId"></param>
        public void DeleteTemplate(string alias, int userId = 0)
        {
            using (var scope = ScopeProvider.CreateScope())
            {
                var template = _templateRepository.Get(alias);
                if (template == null)
                {
                    scope.Complete();
                    return;
                }

                var args = new DeleteEventArgs <ITemplate>(template);
                if (scope.Events.DispatchCancelable(DeletingTemplate, this, args))
                {
                    scope.Complete();
                    return;
                }

                _templateRepository.Delete(template);

                args.CanCancel = false;
                scope.Events.Dispatch(DeletedTemplate, this, args);

                Audit(AuditType.Delete, userId, template.Id, ObjectTypes.GetName(UmbracoObjectTypes.Template));
                scope.Complete();
            }
        }
    public async Task <IActionResult> OnPostDeleteTemplate()
    {
        // TODO: Error handling
        Guid?projectId = await _templateTbl.Query()
                         .Where(x => x.Id.Equals(DeleteTemplate.TemplateId))
                         .Select(x => x.ProjectId)
                         .FirstOrDefaultAsync();

        if (projectId == null)
        {
            throw new NullReferenceException();
        }

        if (DeleteTemplate.ProjectId != projectId)
        {
            throw new ArgumentException(nameof(DeleteTemplate.ProjectId));
        }

        await _templateTbl.Delete(DeleteTemplate.TemplateId);

        await _projectTbl.UpdateFromQuery(x => x.Id.Equals(MarkAsActive.ProjectId), _ => new ProjectTbl
        {
            DateModified = DateTime.Now
        });

        TempData["toastStatus"]  = "success";
        TempData["toastMessage"] = "Template deleted";

        return(RedirectToPage("/Project/Details", new { id = DeleteTemplate.ProjectId }));
    }
Exemple #4
0
        /// <summary>
        /// Deletes a template by its alias
        /// </summary>
        /// <param name="alias">Alias of the <see cref="ITemplate"/> to delete</param>
        /// <param name="userId"></param>
        public void DeleteTemplate(string alias, int userId = Constants.Security.SuperUserId)
        {
            using (ICoreScope scope = ScopeProvider.CreateCoreScope())
            {
                ITemplate?template = _templateRepository.Get(alias);
                if (template == null)
                {
                    scope.Complete();
                    return;
                }

                EventMessages eventMessages        = EventMessagesFactory.Get();
                var           deletingNotification = new TemplateDeletingNotification(template, eventMessages);
                if (scope.Notifications.PublishCancelable(deletingNotification))
                {
                    scope.Complete();
                    return;
                }

                _templateRepository.Delete(template);

                scope.Notifications.Publish(new TemplateDeletedNotification(template, eventMessages).WithStateFrom(deletingNotification));

                Audit(AuditType.Delete, userId, template.Id, ObjectTypes.GetName(UmbracoObjectTypes.Template));
                scope.Complete();
            }
        }
        public ActionResult <Template> DeleteTemplate(int id)
        {
            Template template = _templateRepository.GetTemplateById(id);

            if (template == null && !template.IsActief)
            {
                return(NotFound());
            }
            _templateRepository.Delete(template);
            _templateRepository.SaveChanges();
            return(template);
        }
        public IHttpActionResult Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            if (!HasAccess(id))
            {
                return(Unauthorized());
            }

            _templateRepository.Delete(id);
            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void Can_Perform_Delete_When_Assigned_To_Doc()
        {
            // Arrange
            IScopeProvider   provider        = ScopeProvider;
            var              scopeAccessor   = (IScopeAccessor)provider;
            IDataTypeService dataTypeService = GetRequiredService <IDataTypeService>();
            IFileService     fileService     = GetRequiredService <IFileService>();

            using (provider.CreateScope())
            {
                ITemplateRepository templateRepository = CreateRepository(provider);
                var globalSettings         = new GlobalSettings();
                var serializer             = new JsonNetSerializer();
                var tagRepository          = new TagRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <TagRepository>());
                var commonRepository       = new ContentTypeCommonRepository(scopeAccessor, templateRepository, AppCaches, ShortStringHelper);
                var languageRepository     = new LanguageRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <LanguageRepository>(), Microsoft.Extensions.Options.Options.Create(globalSettings));
                var contentTypeRepository  = new ContentTypeRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <ContentTypeRepository>(), commonRepository, languageRepository, ShortStringHelper);
                var relationTypeRepository = new RelationTypeRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <RelationTypeRepository>());
                var entityRepository       = new EntityRepository(scopeAccessor, AppCaches.Disabled);
                var relationRepository     = new RelationRepository(scopeAccessor, LoggerFactory.CreateLogger <RelationRepository>(), relationTypeRepository, entityRepository);
                var propertyEditors        = new PropertyEditorCollection(new DataEditorCollection(() => Enumerable.Empty <IDataEditor>()));
                var dataValueReferences    = new DataValueReferenceFactoryCollection(() => Enumerable.Empty <IDataValueReferenceFactory>());
                var contentRepo            = new DocumentRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <DocumentRepository>(), LoggerFactory, contentTypeRepository, templateRepository, tagRepository, languageRepository, relationRepository, relationTypeRepository, propertyEditors, dataValueReferences, dataTypeService, serializer, Mock.Of <IEventAggregator>());

                Template template = TemplateBuilder.CreateTextPageTemplate();
                fileService.SaveTemplate(template); // else, FK violation on contentType!

                ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage2", "Textpage", defaultTemplateId: template.Id);
                contentTypeRepository.Save(contentType);

                Content textpage = ContentBuilder.CreateSimpleContent(contentType);
                contentRepo.Save(textpage);

                textpage.TemplateId = template.Id;
                contentRepo.Save(textpage);

                // Act
                ITemplate templates = templateRepository.Get("textPage");
                templateRepository.Delete(templates);

                // Assert
                Assert.IsNull(templateRepository.Get("textPage"));
            }
        }
        public async Task <bool> Delete(User user, Template template)
        {
            try
            {
                var realtemplate = await GetById(user, template.Id);

                if (realtemplate != null)
                {
                    template.fk_UserId = user.Id;
                    template.Deleted   = true;
                    template.DeletedOn = DateTime.Today;
                    return(_templateRepository.Delete(template));
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <IActionResult> Delete(long id)
        {
            var template = await templateRepository.GetByIdAsync(id);

            if (template == null)
            {
                return(JsonNotFound($"Template ID {id} is not found."));
            }

            if (await experimentRepository.ExistsAsync(x => x.TemplateId == id, true))
            {
                return(JsonConflict($"Template {id} has been used by experiment."));
            }
            if (await experimentPreprocessRepository.ExistsAsync(x => x.TemplateId == id, true))
            {
                return(JsonConflict($"Template {id} has been used by experiment preprocess."));
            }

            templateRepository.Delete(template);
            unitOfWork.Commit();
            return(JsonNoContent());
        }
        public bool DelTemplate(int TemplateID)
        {
            try
            {
                var template = _templateRepository.GetById(TemplateID);

                if (template != null)
                {
                    _templateRepository.Delete(template);
                    //_templateRepository.SaveChangesAsync();
                    return(true);
                }
                return(false);
            }
            catch (EntryPointNotFoundException ex)
            {
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #11
0
        public async Task <object> Delete(int id)
        {
            EmailTemplate emailTemplate = new EmailTemplate();

            try
            {
                emailTemplate = _templateRepository.Delete(id);
            }
            catch (Exception ex)
            {
                result = false;
                error  = ex.Message;
            }

            return(new SingleResponse <EmailTemplate>
            {
                Message = "Email template deleted successfully",
                DidError = false,
                ErrorMessage = string.Empty,
                Token = string.Empty,
                Model = emailTemplate
            });
        }
        public void Can_Perform_Delete_On_Nested_Templates()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ITemplateRepository repository = CreateRepository(provider);

                var parent = new Template(ShortStringHelper, "parent", "parent")
                {
                    Content = @"<%@ Master Language=""C#"" %>"
                };
                var child = new Template(ShortStringHelper, "child", "child")
                {
                    Content = @"<%@ Master Language=""C#"" %>"
                };
                var baby = new Template(ShortStringHelper, "baby", "baby")
                {
                    Content = @"<%@ Master Language=""C#"" %>"
                };
                child.MasterTemplateAlias = parent.Alias;
                child.MasterTemplateId    = new Lazy <int>(() => parent.Id);
                baby.MasterTemplateAlias  = child.Alias;
                baby.MasterTemplateId     = new Lazy <int>(() => child.Id);
                repository.Save(parent);
                repository.Save(child);
                repository.Save(baby);

                // Act
                ITemplate templates = repository.Get("parent");
                repository.Delete(templates);

                // Assert
                Assert.IsNull(repository.Get("test"));
            }
        }
Exemple #13
0
 public async Task <bool> Delete(long id)
 {
     return(await _templateRepository.Delete <Templates>(id));
 }
Exemple #14
0
 public void Delete(int id) =>
 _tRepo.Delete(id);
Exemple #15
0
        public async Task Delete(string id)
        {
            await _templates.Delete(id);

            await _cache.Remove(id);
        }
Exemple #16
0
 public void DeleteForm(string keyValue)
 {
     service.Delete(t => t.TEM_ID == keyValue);
 }
 public void Delete(Guid id)
 {
     _repo.Delete(id);
 }
 public async Task Delete(Guid id)
 {
     await _repo.Delete(id);
 }
Exemple #19
0
 public void DeleteTemplate(long id)
 {
     templateRepository.Delete(p => p.Id == id);
 }