public async Task<ForumSectionDto> CreateAsync(string name) { var foundCount = await _forumSectionRepository.GetCountAsync(x => x.Name == name); if (foundCount > 0) { return null; } var model = new ForumSection(name); model = await _forumSectionRepository.AddAsync(model); await _forumSectionRepository.SaveChangesAsync(); var result = _mapper.Map<ForumSectionDto>(model); return result; }
private async Task InitializeForumSections() { if (_context.ForumSections.Any()) return; var forumSection1 = new ForumSection() { Name = "section 1" }; var forumSection2 = new ForumSection() { Name = "section 2" }; _context.ForumSections.Add(forumSection1); _context.ForumSections.Add(forumSection2); await _context.SaveChangesAsync(); }
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(); } }
public void Update(ForumSection entity) { _context.ForumSections.Attach(entity); _context.Entry(entity).State = EntityState.Modified; }
public async Task DeleteAsync(ForumSection entity) { await Task.FromResult(_context.ForumSections.Remove(entity)); }
public async Task<ForumSection> AddAsync(ForumSection entity) { var addedEntity = await _context.ForumSections.AddAsync(entity); return addedEntity.Entity; }