Пример #1
0
 public static D_Notice UnMapNotice(L_Notice notice)
 {
     return(new D_Notice
     {
         NoticeId = notice.NoticeId,
         Description = notice.Description,
         Time = notice.Time
     });
 }
Пример #2
0
        /// <summary> Changes all notice related to a particular existing notice.
        /// <param name="inputNotice"> object L_Notice (name of object) - This is a logic object of type notice. </param>
        /// <returns> void </returns>
        /// </summary>
        public async Task UpdateNotice(L_Notice inputNotice)
        {
            _logger.LogInformation($"Updating notice with ID {inputNotice.NoticeId}");
            D_Notice currentEntity = await _dbContext.Notices.FindAsync(inputNotice.NoticeId);

            D_Notice newEntity = Mapper.UnMapNotice(inputNotice);

            _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity);
            Save();
        }
Пример #3
0
 private bool compareNoticeL(L_Notice x, L_Notice y)
 {
     if (
         x.NoticeId != y.NoticeId ||
         x.Description != y.Description ||
         x.Time != y.Time
         )
     {
         return(false);
     }
     return(true);
 }
Пример #4
0
        public async Task <IActionResult> Put(int id, [FromBody] L_Notice notice)
        {
            // successful update for PUT returns 204 No Content with empty body, or 200 OK
            if (await _noticeRepository.GetNoticeById(id) is L_Notice oldNotice)
            {
                await _noticeRepository.UpdateNotice(notice);

                return(NoContent());
                //return StatusCode(204);
            }
            return(NotFound());
        }
Пример #5
0
        /// <summary> Adds a new notice to the database.
        /// <param name="inputNotice"> object L_Notice (name of object) - This is a logic object of type notice. </param>
        /// <returns> void </returns>
        /// </summary>
        public void AddNotice(L_Notice inputNotice)
        {
            if (inputNotice.NoticeId != 0)
            {
                _logger.LogWarning($"Notice to be added has an ID ({inputNotice.NoticeId}) already!");
                throw new ArgumentException("Id already exists when trying to add a new notice!", $"{inputNotice.NoticeId}");
            }

            _logger.LogInformation("Adding notice.");

            D_Notice entity = Mapper.UnMapNotice(inputNotice);

            entity.NoticeId = 0;
            _dbContext.Add(entity);
            Save();
        }
Пример #6
0
        public void UnMapNoticeTest()
        {
            DateTime myTime        = new DateTime(1000, 10, 10);
            L_Notice sampleNoticeL = new L_Notice
            {
                NoticeId    = 100,
                Description = "Test Notice.",
                Time        = myTime
            };

            D_Notice sampleNoticeD = new D_Notice
            {
                NoticeId    = 100,
                Description = "Test Notice.",
                Time        = myTime
            };

            D_Notice resultNoticeD = Mapper.UnMapNotice(sampleNoticeL);

            Assert.True(compareNoticeD(resultNoticeD, sampleNoticeD));
        }
Пример #7
0
 public IActionResult Post(L_Notice notice)
 {
     _noticeRepository.AddNotice(notice);
     return(CreatedAtAction(nameof(GetById), new { id = notice.NoticeId }, notice));
 }