public RecoveryController( IRepository<Post> postRepository, IRepository<Redirect> redirectRepository, IRepository<BlogTemplate> styleRepository, IRepository<User> userRepository, IRepository<Securable> securableRepository, IRepository<TemporaryUploadedBlogBackup> tempBlogBackupRepo, IRepository<Data.Blog> blogRepository, ISecurityHelper securityHelper, IHttpContextService httpContext) : base(blogRepository, httpContext, securityHelper, userRepository, securableRepository) { _postRepository = postRepository; _redirectRepository = redirectRepository; _styleRepository = styleRepository; _tempBlogBackupRepo = tempBlogBackupRepo; _userRepository = userRepository; _blogRepository = blogRepository; _securityHelper = securityHelper; //Naieve clean of the collection to avoid leaks in long running instances of the application var toDelete = _tempBlogBackupRepo.GetAll().Where(b => b.UploadTime < DateTime.Now.AddHours(-1)).ToArray(); foreach(var toDel in toDelete) { _tempBlogBackupRepo.Delete(toDel); } }
public HasTagsHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) { OnLoading<HasTags>((context, tags) => { // provide names of all tags on demand tags._allTags.Loader(list => tagsRepository.Table.ToList()); // populate list of attached tags on demand tags._currentTags.Loader(list => { var tagsContentItems = tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id); foreach (var tagContentItem in tagsContentItems) { var tag = tagsRepository.Get(tagContentItem.TagId); list.Add(tag); } return list; }); }); OnRemoved<HasTags>((context, ht) => { tagsContentItemsRepository.Flush(); HasTags tags = context.ContentItem.As<HasTags>(); foreach (var tag in tags.CurrentTags) { if (!tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id).Any()) { tagsRepository.Delete(tag); } } }); }
public FaqTypeHandler(IRepository<FaqTypePartRecord> repository) { Filters.Add(StorageFilter.For(repository)); OnRemoved<FaqTypePart>((context, part) => repository.Delete(part.Record)); OnIndexing<FaqTypePart>((context, contactPart) => context.DocumentIndex.Add("faqtype_title", contactPart.Title).Analyze().Store()); }
public FaqHandler(IRepository<FaqPartRecord> repository) { Filters.Add(StorageFilter.For(repository)); OnRemoved<FaqPart>((context, part) => repository.Delete(part.Record)); OnIndexing<FaqPart>((context, contactPart) => context.DocumentIndex.Add("faq_question", contactPart.Question).Analyze().Store()); }
public CacheModule(IRepository repository) { Get["/api/pull/clear/transactions"] = _ => { repository.Delete<Transaction>(); return View["/"]; }; }
private void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, BlogPostPart blogPostPart) { blogArchiveRepository.Flush(); var commonPart = blogPostPart.As<CommonPart>(); if(commonPart == null || !commonPart.CreatedUtc.HasValue) return; // get the time zone for the current request var timeZone = _workContextAccessor.GetContext().CurrentTimeZone; var previousCreatedUtc = _previousCreatedUtc.ContainsKey(blogPostPart) ? _previousCreatedUtc[blogPostPart] : DateTime.MinValue; previousCreatedUtc = TimeZoneInfo.ConvertTimeFromUtc(previousCreatedUtc, timeZone); var previousMonth = previousCreatedUtc.Month; var previousYear = previousCreatedUtc.Year; var newCreatedUtc = commonPart.CreatedUtc; newCreatedUtc = newCreatedUtc.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(newCreatedUtc.Value, timeZone) : newCreatedUtc; var newMonth = newCreatedUtc.HasValue ? newCreatedUtc.Value.Month : 0; var newYear = newCreatedUtc.HasValue ? newCreatedUtc.Value.Year : 0; // if archives are the same there is nothing to do if (previousMonth == newMonth && previousYear == newYear) { return; } // decrement previous archive record var previousArchiveRecord = blogArchiveRepository.Table .Where(x => x.BlogPart == blogPostPart.BlogPart.Record && x.Month == previousMonth && x.Year == previousYear) .FirstOrDefault(); if (previousArchiveRecord != null && previousArchiveRecord.PostCount > 0) { previousArchiveRecord.PostCount--; } // if previous count is now zero, delete the record if (previousArchiveRecord != null && previousArchiveRecord.PostCount == 0) { blogArchiveRepository.Delete(previousArchiveRecord); } // increment new archive record var newArchiveRecord = blogArchiveRepository.Table .Where(x => x.BlogPart == blogPostPart.BlogPart.Record && x.Month == newMonth && x.Year == newYear) .FirstOrDefault(); // if record can't be found create it if (newArchiveRecord == null) { newArchiveRecord = new BlogPartArchiveRecord { BlogPart = blogPostPart.BlogPart.Record, Year = newYear, Month = newMonth, PostCount = 0 }; blogArchiveRepository.Create(newArchiveRecord); } newArchiveRecord.PostCount++; }
public CampaignCategoriesHandler(IRepository<CampaignCategoriesRecord> repository) { Filters.Add(StorageFilter.For(repository)); OnRemoved<CampaignCategoriesPart>((context, part) => { repository.Delete(part.Record); }); }
public MailChimpSettingsPartHandler(IRepository<MailChimpSettingsPartRecord> repository) { Filters.Add(StorageFilter.For(repository)); OnRemoved<MailChimpSettingsPart>((context, part) => { repository.Delete(part.Record); }); }
public FaqEntryPartHandler(IRepository<FaqEntryPartRecord> repository) { Filters.Add(StorageFilter.For(repository)); OnRemoved<FaqEntryPart>((context, part) => { repository.Delete(part.Record); }); }
public void Delete(int id) { DAL.DataEntities.Configuration DALConfiguration; using (_ConfigurationRepository = new GenericRepository<DAL.DataEntities.Configuration>()) { DALConfiguration = _ConfigurationRepository.SingleOrDefault(m => m.ID == id); _ConfigurationRepository.Delete(DALConfiguration); _ConfigurationRepository.SaveChanges(); } }
public void Delete(int id) { DAL.DataEntities.Model model; using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>()) { model = _ModelRepository.SingleOrDefault(m => m.ID == id); _ModelRepository.Delete(model); _ModelRepository.SaveChanges(); } }
public void Delete(int id) { DAL.DataEntities.UITemplate template; using (_UITemplateRepository = new GenericRepository<DAL.DataEntities.UITemplate>()) { template = _UITemplateRepository.SingleOrDefault(m => m.ID == id); _UITemplateRepository.Delete(template); _UITemplateRepository.SaveChanges(); } }
public void Delete_Should_Remove_Item_By_Key(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var result = repository.Get(contact.ContactId); result.ShouldNotBeNull(); repository.Delete(contact.ContactId); result = repository.Get(contact.ContactId); result.ShouldBeNull(); }
public static void DeleteTags(IRepository<DalTagEntity> repository, int idArticle) { var tags = repository.GetAll() .Where(c => c.Article != null) .Where(c => c.Article.Id == idArticle) .Select(c => c) .ToList(); foreach (var item in tags) { repository.Delete(item); } }
public static void DeleteComments(IRepository<DalCommentEntity> repository, int idUser) { var comments = repository.GetAll() .Where(c => c.User != null) .Where(c => c.User.Id == idUser) .Select(c => c) .ToList(); foreach (var item in comments) { repository.Delete(item); } }
public void SetUp() { _repository = new Repository<Opinion>(() => new JudgifyContext()); // Nie rozumiem FakeItEasy, nie ruszam tego póki co. //_repository = A.Fake<IRepository<Category>>(); _sut = new OpinionService(_repository); foreach (var opinion in _repository.GetAll()) { _repository.Delete(opinion); } }
public AdvancedMenuItemPartHandler(IRepository<AdvancedMenuItemPartRecord> repository) { Filters.Add(StorageFilter.For(repository)); OnLoaded<AdvancedMenuItemPart>((ctx, part) => { var relatedItem = ctx.ContentManager.Get(part.Record.RelatedContentId); if (relatedItem != null) { part.RelatedItem = relatedItem; part.RouteValues = ctx.ContentManager.GetItemMetadata(relatedItem).DisplayRouteValues; } }); OnRemoved<AdvancedMenuItemPart>((ctx, part) => repository.Delete(part.Record)); }
public static void DeleteBlogs(IRepository<DalBlogEntity> blogRepository, IRepository<DalArticleEntity> articleRepository, IRepository<DalTagEntity> tagRepository, int id) { var blogs = blogRepository.GetAll() .Where(c => c.User != null) .Where(c => c.User.Id == id) .Select(c => c) .ToList(); foreach (var item in blogs) { DeleteArticles(articleRepository, tagRepository, item.Id); blogRepository.Delete(item); } }
public static void DeleteArticles(IRepository<DalArticleEntity> artRepository, IRepository<DalTagEntity> tagRepository, int id) { var articles = artRepository.GetAll() .Where(c => c.Blog != null) .Where(c => c.Blog.Id == id) .Select(c => c) .ToList(); foreach (var item in articles) { DeleteTags(tagRepository, item.Id); artRepository.Delete(item); } }
public WorkflowHandler( IRepository<WorkflowRecord> workflowRepository ) { // Delete any pending workflow related to a deleted content item OnRemoving<ContentPart>( (context, part) => { var workflows = workflowRepository.Table.Where(x => x.ContentItemRecord == context.ContentItemRecord).ToList(); foreach (var item in workflows) { workflowRepository.Delete(item); } }); }
public override void Execute( Job job, Action<string> updateStatus, IRepository repositoryService, IJobManager jobManager) { Console.WriteLine("Press any key to begin deleting files..."); Console.ReadKey(); foreach(var file in job.Files) { updateStatus(string.Format("Deleting file: \"{0}\"...", file.Name)); repositoryService.Delete(file.Link.Id); } }
public void Common_CanDelete(IRepository<Product> db) { db.Save(new Product { ProductName = "Optimus", Category = "Autobots", MinimumPrice = 7 }); var px = new Product { ProductName = "Bumble Bee", Category = "Autobots", MinimumPrice = 8 }; db.Save(px); db.Save(new Product { ProductName = "Megatron", Category = "Decepticon", MinimumPrice = 9 }); db.Delete(px.ProductId, px.RowVersion); Assert.AreEqual(7 + 9, db.All.Sum(x => x.MinimumPrice)); Assert.AreEqual(null, db.Get(px.ProductId)); Assert.AreEqual(2, db.All.Count()); }
protected override bool ExecuteWithData(string cmd, IRepository repo, Player player) { var name = cmd.Split(new[] {' '}, 2)[1]; var go = goQueries.GetGameObjectByNameAndPlayerLocation(repo, name, player); if (go == null) { console.WriteLine("You don't see anything like that around"); return false; } else { console.Write("You just deleted: "); console.WriteLine(go.Name); repo.Delete(go); return true; } }
public void Delete_Should_Remove_Multiple_Items(IRepository<Contact, string> repository) { IList<Contact> contacts = new List<Contact> { new Contact {Name = "Contact 1"}, new Contact {Name = "Contact 2"}, new Contact {Name = "Contact 3"}, }; repository.Add(contacts); var items = repository.GetAll().ToList(); items.Count().ShouldEqual(3); repository.Delete(contacts.Take(2)); items = repository.GetAll().ToList(); items.Count().ShouldEqual(1); items.First().Name.ShouldEqual("Contact 3"); }
public void Delete_Predicate_Should_Remove_Multiple_Items(IRepository<Contact, string> repository) { IList<Contact> contacts = new List<Contact> { new Contact {Name = "Contact 1", ContactTypeId = 1}, new Contact {Name = "Contact 2", ContactTypeId = 1}, new Contact {Name = "Contact 3", ContactTypeId = 3}, }; repository.Add(contacts); var items = repository.GetAll().ToList(); items.Count().ShouldEqual(3); repository.Delete(x => x.ContactTypeId < 3); items = repository.GetAll().ToList(); items.Count().ShouldEqual(1); items.First().Name.ShouldEqual("Contact 3"); }
private static void SampleMethod(IRepository<Product,int?> productRepository) { SessionProvider.RebuildSchema(); //Create a Product var pNew = new Product { ProductName = "Canned Salmon" }; productRepository.Save(pNew); //Get a Product var pGet = productRepository.GetById(pNew.ProductId); //Update a Product pGet.ProductName = "Canned Tuna"; productRepository.Save(pGet); //Delete a Product productRepository.Delete(pNew); }
public void Delete_By_Params_Should_Remove_Multiple_Items(IRepository<Contact, string> repository) { var contact1 = new Contact {Name = "Contact 1", ContactTypeId = 1}; var contact2 = new Contact {Name = "Contact 2", ContactTypeId = 1}; var contact3 = new Contact {Name = "Contact 3", ContactTypeId = 3}; repository.Add(contact1); repository.Add(contact2); repository.Add(contact3); var items = repository.GetAll().ToList(); items.Count().ShouldEqual(3); repository.Delete(contact1.ContactId, contact2.ContactId); items = repository.GetAll().ToList(); items.Count().ShouldEqual(1); items.First().Name.ShouldEqual("Contact 3"); }
private static void RefreshExistingPhoneNumbers(User destination, UserDTO source, IRepository<PhoneNumber> phoneNumberRepository) { source.PhoneNumbers.Where(x => !x.IsNew()).ToList().ForEach(updatedPhoneNumber => { var domainPhoneNumber = destination.PhoneNumbers.FirstOrDefault(x => x.Id == updatedPhoneNumber.Id); if (domainPhoneNumber == null) { throw new ArgumentNullException("You trying to update phone number which is actually doesn't exists in database"); } if (updatedPhoneNumber.ShouldBeRemoved()) { phoneNumberRepository.Delete(updatedPhoneNumber.Id); } else { domainPhoneNumber.Update(updatedPhoneNumber); } }); }
private static void PerformPhotoSaving(User destination, UserDTO source, IRepository<File> fileRepository) { var photoInDTO = source.Photo; if (photoInDTO != null) { var photoInDb = fileRepository.GetByID(source.Photo.Id); if (photoInDb == null) { throw new Exception("Database doesn't contains such entity"); } if (photoInDTO.ShouldBeRemoved()) { fileRepository.Delete(photoInDb.Id); } else { photoInDb.Update(photoInDTO); destination.Photo = photoInDb; } } }
private void ReduceBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, BlogPostPart blogPostPart) { blogArchiveRepository.Flush(); var commonPart = blogPostPart.As<CommonPart>(); if (commonPart == null || !commonPart.CreatedUtc.HasValue) return; var timeZone = _workContextAccessor.GetContext().CurrentTimeZone; var datetime = TimeZoneInfo.ConvertTimeFromUtc(commonPart.CreatedUtc.Value, timeZone); var previousArchiveRecord = blogArchiveRepository.Table .FirstOrDefault(x => x.BlogPart == blogPostPart.BlogPart.Record && x.Month == datetime.Month && x.Year == datetime.Year); if(previousArchiveRecord == null) return; if (previousArchiveRecord.PostCount > 0) previousArchiveRecord.PostCount--; else blogArchiveRepository.Delete(previousArchiveRecord); }