public async Task TestAddNotice() { try { Notice notice = new Notice() { Name = "notice2", TimeCompleted = DateTime.UtcNow.AddDays(2) }; notice = await _noticesRepository.AddNoticeAsync("60848ae8fb71edf2a7ebf846", notice); Assert.NotNull(notice.TimeCreated); IEnumerable <Notice> notices = await _noticesRepository.GetNoticesAsync("60848ae8fb71edf2a7ebf846"); Assert.AreEqual(2, notices.Count()); } catch (Exception ex) { throw ex; } finally { await _usersRepository.DeleteUserAsync("60848ae8fb71edf2a7ebf846"); } }
public async Task <IActionResult> AddNoticeAsync(AddNoticeDto model) { try { string userId = User.Claims.FirstOrDefault(c => c.Type == JwtRegisteredClaimNames.Sub).Value; Notice addNoticeDto = _mapper.Map <Notice>(model); Notice notice = await _noticesRepository.AddNoticeAsync(userId, addNoticeDto); return(Ok(notice)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }