当前位置: 首页>>代码示例>>C#>>正文


C# IRepository.Create方法代码示例

本文整理汇总了C#中IRepository.Create方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.Create方法的具体用法?C# IRepository.Create怎么用?C# IRepository.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRepository的用法示例。


在下文中一共展示了IRepository.Create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RecalculateBlogArchive

        private static void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService, BlogPostPart blogPostPart)
        {
            blogArchiveRepository.Flush();

            // remove all current blog archive records
            var blogArchiveRecords =
                from bar in blogArchiveRepository.Table
                where bar.BlogPart == blogPostPart.BlogPart.Record
                select bar;
            blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete);

            // get all blog posts for the current blog
            var posts = blogPostService.Get(blogPostPart.BlogPart, VersionOptions.Published);

            // create a dictionary of all the year/month combinations and their count of posts that are published in this blog
            var inMemoryBlogArchives = new Dictionary<DateTime, int>();
            foreach (var post in posts) {
                if (!post.Has<CommonPart>())
                    continue;

                var commonPart = post.As<CommonPart>();
                var key = new DateTime(commonPart.CreatedUtc.Value.Year, commonPart.CreatedUtc.Value.Month, 1);

                if (inMemoryBlogArchives.ContainsKey(key))
                    inMemoryBlogArchives[key]++;
                else
                    inMemoryBlogArchives[key] = 1;
            }

            // create the new blog archive records based on the in memory values
            foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) {
                blogArchiveRepository.Create(new BlogPartArchiveRecord {BlogPart = blogPostPart.BlogPart.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value});
            }
        }
开发者ID:galyna,项目名称:maozedong-orchard1,代码行数:34,代码来源:BlogPartArchiveHandler.cs

示例2: RecalculateTimetableArchive

        private static void RecalculateTimetableArchive(IRepository<TimetablePartArchiveRecord> TimetableArchiveRepository, ITimetableAppointmentService TimetableAppointmentService, TimetableAppointmentPart TimetableAppointmentPart) {
            TimetableArchiveRepository.Flush();

            // remove all current Timetable archive records
            var TimetableArchiveRecords =
                from bar in TimetableArchiveRepository.Table
                where bar.TimetablePart == TimetableAppointmentPart.TimetablePart.Record
                select bar;
            TimetableArchiveRecords.ToList().ForEach(TimetableArchiveRepository.Delete);

            // get all Timetable appointments for the current Timetable
            var appointments = TimetableAppointmentService.Get(TimetableAppointmentPart.TimetablePart, VersionOptions.Published);

            // create a dictionary of all the year/month combinations and their count of appointments that are published in this Timetable
            var inMemoryTimetableArchives = new Dictionary<DateTime, int>(appointments.Count());
            foreach (var appointment in appointments) {
                if (!appointment.Has<CommonPart>())
                    continue;

                var commonPart = appointment.As<CommonPart>();
                var key = new DateTime(commonPart.PublishedUtc.Value.Year, commonPart.PublishedUtc.Value.Month, 1);

                if (inMemoryTimetableArchives.ContainsKey(key))
                    inMemoryTimetableArchives[key]++;
                else
                    inMemoryTimetableArchives[key] = 1;
            }

            // create the new Timetable archive records based on the in memory values
            foreach (KeyValuePair<DateTime, int> item in inMemoryTimetableArchives) {
                TimetableArchiveRepository.Create(new TimetablePartArchiveRecord {TimetablePart = TimetableAppointmentPart.TimetablePart.Record, Year = item.Key.Year, Month = item.Key.Month, AppointmentCount = item.Value});
            }
        }
开发者ID:dminik,项目名称:voda_code,代码行数:33,代码来源:TimetablePartArchiveHandler.cs

示例3: Given_Repository

        public void Given_Repository(bool cleanFolders)
        {
            if(cleanFolders)
                DeleteFiles();

            serializer = new ItemJsonSerializer(dataPath);

            repo = new ItemRepository(serializer);

            repo.DataPath = dataPath;

            projectItem = repo.Create<Project>() as Project;
            storyItem = repo.Create<Story>() as Story;
            scenarioItem = repo.Create<Scenario>() as Scenario;
            interactionItem = new Interaction();
            dataItem = new DataItem();
        }
开发者ID:ihenehan,项目名称:Behavior,代码行数:17,代码来源:when_creating_new_items.cs

示例4: RecalculateBlogArchive

        private static void RecalculateBlogArchive(IRepository<BlogArchiveRecord> blogArchiveRepository, IRepository<CommonRecord> commonRepository, BlogPost blogPost) {
            blogArchiveRepository.Flush();

            //INFO: (erikpo) Remove all current blog archive records
            var blogArchiveRecords =
                from bar in blogArchiveRepository.Table
                where bar.Blog == blogPost.Blog.Record
                select bar;
            blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete);

            //INFO: (erikpo) Get all blog posts for the current blog
            var postsQuery =
                from bpr in commonRepository.Table
                where bpr.ContentItemRecord.ContentType.Name == BlogPostDriver.ContentType.Name && bpr.Container.Id == blogPost.Blog.Record.Id
                orderby bpr.PublishedUtc
                select bpr;

            //INFO: (erikpo) Create a dictionary of all the year/month combinations and their count of posts that are published in this blog
            var inMemoryBlogArchives = new Dictionary<DateTime, int>(postsQuery.Count());
            foreach (var post in postsQuery) {
                if (!post.PublishedUtc.HasValue)
                    continue;

                var key = new DateTime(post.PublishedUtc.Value.Year, post.PublishedUtc.Value.Month, 1);

                if (inMemoryBlogArchives.ContainsKey(key))
                    inMemoryBlogArchives[key]++;
                else
                    inMemoryBlogArchives[key] = 1;
            }

            //INFO: (erikpo) Create the new blog archive records based on the in memory values
            foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) {
                blogArchiveRepository.Create(new BlogArchiveRecord {Blog = blogPost.Blog.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value});
            }
        }
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:36,代码来源:BlogArchiveHandler.cs

示例5: RecalculateBlogArchive

        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++;            
        }
开发者ID:bigfont,项目名称:CertifiedOverheadCrane,代码行数:58,代码来源:BlogPartArchiveHandler.cs


注:本文中的IRepository.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。