/// <summary> /// Creates a new chapter detail /// </summary> /// <param name="chapterDetail">Chapter detail</param> /// <returns>Chapter detail filled with data</returns> public async Task <AikaChapterDetail> CreateChapterDetail(AikaChapterDetail chapterDetail) { chapterDetail.Id = Guid.NewGuid().ToString(); await _ChapterDetailCollection.InsertOneAsync(chapterDetail); return(chapterDetail); }
/// <summary> /// Deletes a chapter detail /// </summary> /// <param name="chapterDetail">Chapter detail to delete</param> /// <returns>Task</returns> public async Task DeleteChapterDetail(AikaChapterDetail chapterDetail) { AikaChapterDetail existingChapterDetail = await GetChapterDetailById(chapterDetail.Id); if (existingChapterDetail == null) { throw new NullReferenceException(); } IMongoCollection <AikaChapterDetail> recyclingBin = _Database.GetCollection <AikaChapterDetail>(AikaChapterDetailRecyclingBinCollectionName); await recyclingBin.InsertOneAsync(existingChapterDetail); DeleteResult result = await _ChapterDetailCollection.DeleteOneAsync(c => c.Id == chapterDetail.Id); }
/// <summary> /// Updates a chapter detail /// </summary> /// <param name="chapterDetail">Chapter detail to update</param> /// <returns>Task</returns> public async Task UpdateChapterDetail(AikaChapterDetail chapterDetail) { ReplaceOneResult result = await _ChapterDetailCollection.ReplaceOneAsync(c => c.Id == chapterDetail.Id, chapterDetail); }
/// <summary> /// Returns a chapter detail by the id /// </summary> /// <param name="id">Id of the chapter detail</param> /// <returns>Chapter detail</returns> public async Task <AikaChapterDetail> GetChapterDetailById(string id) { AikaChapterDetail chapterDetail = await _ChapterDetailCollection.Find(c => c.Id == id).FirstOrDefaultAsync(); return(chapterDetail); }