コード例 #1
0
        private async Task InitializeForumSubsections()
        {
            if (_context.ForumSubsections.Any()) return;
            var forumSubsection1 = new ForumSubsection()
            {
                Name = "subsection 1",
                Description = "subsection description 1",
                SectionId = 1,

            };
            var forumSubsection2 = new ForumSubsection()
            {
                Name = "subsection 2",
                Description = "subsection description 2",
                SectionId = 1
            };
            _context.ForumSubsections.Add(forumSubsection1);
            _context.ForumSubsections.Add(forumSubsection2);
            await _context.SaveChangesAsync();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: parys/MyLiverpool
        private static void UpdateForumSectionsAndPopulateSubsectionList()
        {
            Console.WriteLine("Start UpdateForumSections");
            using (FileStream fs = new FileStream(Path + "fr_fr.txt", FileMode.Open))
            {
                byte[] data = new byte[fs.Length];
                fs.Read(data, 0, Convert.ToInt32(fs.Length));

                char[] chars = Encoding.UTF8.GetString(data).ToCharArray();
                var limit = chars.Length;
                if (UseLimit && MaxChars < chars.Length)
                {
                    limit = MaxChars;
                }
                for (int i = 0; i < limit; i++)
                {
                    if (chars[i + 2] == '0' || chars[i + 3] == '0')
                    {
                        ForumSection forumSection = new ForumSection();
                        string id = null;
                        while (chars[i] != '|')
                        {
                            id += chars[i];
                            i++;
                        }
                        i++;
                        forumSection.IdOld = int.Parse(id);
                        // section id
                        while (chars[i] != '|')
                        {
                            i++;
                        }
                        i++;
                        // is section
                        while (chars[i] != '|')
                        {
                            i++;
                        }
                        i++;
                        // sequence
                        while (chars[i] != '|')
                        {
                            i++;
                        }
                        i++;
                        // time creation
                        while (chars[i] != '|')
                        {
                            i++;
                        }
                        i++;
                        // name
                        while (chars[i] != '|')
                        {
                            forumSection.Name += chars[i];
                            i++;
                        }
                        ForumSectionRepository.AddAsync(forumSection);
                        while (chars[i] != 10)
                        {
                            i++;
                        }
                    }
                    else
                    {
                        ForumSubsection forumSubsection = new ForumSubsection();
                        // id
                        string id = null;
                        while (chars[i] != '|')
                        {
                            id += chars[i];
                            i++;
                        }
                        i++;
                        forumSubsection.IdOld = int.Parse(id);
                        // section id
                        string sectionId = null;
                        while (chars[i] != '|')
                        {
                            sectionId += chars[i];
                            i++;
                        }
                        i++;

                        forumSubsection.SectionId = int.Parse(sectionId);
                        // is section
                        while (chars[i] != '|')
                        {
                            i++;
                        }
                        i++;
                        // sequence
                        while (chars[i] != '|')
                        {
                            i++;
                        }
                        i++;
                        // sequence
                        while (chars[i] != '|')
                        {
                            i++;
                        }
                        i++;
                        // name 
                        while (chars[i] != '|')
                        {
                            forumSubsection.Name += chars[i];
                            i++;
                        }
                        i++;
                        // description 
                        while (chars[i] != '|')
                        {
                            forumSubsection.Description += chars[i];
                            i++;
                        }
                        i++;
                        // last modified

                        Subsections.Add(forumSubsection);
                        //     UnitOfWork.ForumSubsectionRepository.Add(forumSubsection);
                        while (chars[i] != 10)
                        {
                            i++;
                        }
                    }
                }
               //? UnitOfWork.Save();
                ForumSectionRepository.SaveChangesAsync();
            }
        }
コード例 #3
0
 public async Task DeleteAsync(ForumSubsection entity)
 {
     await Task.FromResult(_context.ForumSubsections.Remove(entity));
 }
コード例 #4
0
 public void Update(ForumSubsection entity)
 {
     _context.ForumSubsections.Attach(entity);
     _context.Entry(entity).State = EntityState.Modified;
 }
コード例 #5
0
 public async Task<ForumSubsection> AddAsync(ForumSubsection entity)
 {
     var addedEntity = await _context.ForumSubsections.AddAsync(entity);
     return addedEntity.Entity;
 }