public async Task <AuthResponse> UpdateAsync(Guid?topicId, Guid?chapterId, ChapterRequest chapterRequest) { var response = await _httpService.Put <ChapterRequest, AuthResponse>($"{topics}/{topicId}/{chapter}/{chapterId}", chapterRequest); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } return(response.Response); }
public async Task <bool> EditAsync(ChapterRequest chapterRequest, string GetUserId, Guid TopicsId, Guid chapterId) { var topicOwn = await _context.Chapters .Include(b => b.Topics) .ThenInclude(x => x.Invitees) .AnyAsync(s => ( s.Topics.Invitees.Any(r => r.AppUserId.Equals(GetUserId) && r.RequestStatus.Equals(true)) || s.Topics.AppUserId.Equals(GetUserId) ) && s.Topics.Id.Equals(TopicsId)); if (!topicOwn) { return(false); } var chapterExist = await _context.Chapters .AnyAsync(s => s.Name.Equals(chapterRequest.Name) && s.TopicsId.Equals(TopicsId)); var chapter = await GetChapterIdAsync(GetUserId, chapterId, TopicsId); if (chapter == null) { return(false); } if (chapterExist) { return(false); } var chapterName = chapter.Name; chapter.Name = chapterRequest.Name; chapter.TopicsId = TopicsId; _context.Chapters.Update(chapter); var created = await _context.SaveChangesAsync(); var nameId = chapter.Id; await _hubContext.Clients.Group(TopicsId.ToString()).SendAsync("Change", chapterName, nameId, chapterRequest.Name); return(created > 0); }
public async Task <IActionResult> Create([FromRoute] Guid topicsId, [FromBody] ChapterRequest chapterRequest) { var chapter = await _chapterService.CreateAsync(chapterRequest, GetUserId(), topicsId); if (!chapter) { return(Ok(new AuthResponse { Error = "The Name Already Exist" })); } return(Ok(new AuthResponse { Token = "The chapter is Created" })); }
public async Task <bool> CreateAsync(ChapterRequest chapterRequest, string GetUserId, Guid TopicsId) { var topicOwn = await _context.Topics .Include(s => s.Invitees) .AnyAsync(x => x.Id.Equals(TopicsId) && ( x.AppUserId.Equals(GetUserId) || x.Invitees.Any(r => r.AppUserId.Equals(GetUserId) && r.RequestStatus.Equals(true)) )); if (!topicOwn) { return(false); } var chapterExist = await _context.Chapters .AnyAsync(s => s.Name.Equals(chapterRequest.Name) && s.TopicsId.Equals(TopicsId)); if (chapterExist) { return(false); } var chapter = new Chapter { Id = Guid.NewGuid(), Name = chapterRequest.Name, CreatedDate = DateTime.Now, TopicsId = TopicsId }; var nameId = chapter.Id; _context.Chapters.Add(chapter); var created = await _context.SaveChangesAsync(); await _hubContext.Clients.Group(TopicsId.ToString()).SendAsync("Notification", chapterRequest.Name, nameId); return(created > 0); }