예제 #1
0
        public async Task TestUpdateNotice()
        {
            Func <string, string, Notice> getNotice = (userId, noticeId) =>
                                                      _usersCollection.Find(u => u.Id == userId).FirstOrDefault()
                                                      .Notices.Where(n => n.Id == noticeId).FirstOrDefault();

            const string UserId   = "60848ae8fb71edf2a7ebf846";
            const string NoticeId = "608235aea059ac5c9af6da20";

            try
            {
                Notice notice = getNotice(UserId, NoticeId);
                Assert.NotNull(notice);

                notice.Name = "Name Changed";
                await _noticesRepository.UpdateNoticeAsync(notice);

                notice = getNotice(UserId, NoticeId);
                Assert.AreEqual("Name Changed", notice.Name);

                DateTime oldTime = notice.TimeCompleted;
                notice.TimeCompleted = notice.TimeCompleted.AddMinutes(30);
                await _noticesRepository.UpdateNoticeAsync(notice);

                notice = getNotice(UserId, NoticeId);
                Assert.AreNotEqual(oldTime, notice.TimeCompleted);

                notice.Name          = "changed again";
                notice.TimeCompleted = oldTime;
                await _noticesRepository.UpdateNoticeAsync(notice);

                notice = getNotice(UserId, NoticeId);
                Assert.AreEqual("changed again", notice.Name);
                Assert.AreEqual(oldTime, notice.TimeCompleted);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                await _usersRepository.DeleteUserAsync("60848ae8fb71edf2a7ebf846");
            }
        }
예제 #2
0
        public async Task <IActionResult> UpdateNoticeAsync(string id, UpdateNoticeDto model)
        {
            try
            {
                string userId = User.Claims.FirstOrDefault(c => c.Type == JwtRegisteredClaimNames.Sub).Value;
                Notice notice = _mapper.Map <Notice>(model);
                notice.Id     = id;
                notice.UserId = userId;

                await _noticesRepository.UpdateNoticeAsync(notice);

                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }