Example #1
0
        /// <summary> Fetches one notice related to its id.
        /// <param name="noticeId"> int (notice id) </param>
        /// <returns> A single notice related to input id </returns>
        /// </summary>
        public async Task <L_Notice> GetNoticeById(int noticeId)
        {
            _logger.LogInformation($"Retrieving notice with id: {noticeId}");
            D_Notice returnNotice = await _dbContext.Notices
                                    .FirstOrDefaultAsync(p => p.NoticeId == noticeId);

            return(Mapper.MapNotice(returnNotice));
        }
Example #2
0
// ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// ! --------  NOTICE  -----------
// ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        public static L_Notice MapNotice(D_Notice notice)
        {
            return(new L_Notice
            {
                NoticeId = notice.NoticeId,
                Description = notice.Description,
                Time = notice.Time
            });
        }
Example #3
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();
        }
Example #4
0
 private bool compareNoticeD(D_Notice x, D_Notice y)
 {
     if (
         x.NoticeId != y.NoticeId ||
         x.Description != y.Description ||
         x.Time != y.Time
         )
     {
         return(false);
     }
     return(true);
 }
Example #5
0
        /// <summary> Deletes one notice related to a notice id.
        /// <param name="noticeId"> int (notice id) </param>
        /// <returns> void </returns>
        /// </summary>
        public async Task DeleteNoticeById(int noticeId)
        {
            _logger.LogInformation($"Deleting notice with ID {noticeId}");
            D_Notice entity = await _dbContext.Notices.FindAsync(noticeId);

            if (entity == null)
            {
                _logger.LogInformation($"Notice ID {noticeId} not found to delete! : Returning.");
                return;
            }
            _dbContext.Remove(entity);
            Save();
        }
Example #6
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();
        }
Example #7
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));
        }