/// <summary> /// Add new notification to the database /// </summary> /// <param name="notificationDTO">NotificationDTO object</param> /// <returns>Task<int></returns> public async Task<int> AddNewNotification(NotificationDTO notificationDTO) { using (loggingHelper.RMTraceManager.StartTrace("Business.AddNewNotification")) { string methodName = MethodHelper.GetActualAsyncMethodName(); loggingHelper.Log(methodName + LoggerTraceConstants.COLON + LoggerTraceConstants.MethodExecutionStarted, TraceEventType.Verbose, null, LoggerTraceConstants.Category, LoggerTraceConstants.NotificationAPIPriority, LoggerTraceConstants.NotificationBusinessServiceMethodEntryEventId, LoggerTraceConstants.Title); try { NotificationDataDTO notificationDataDTO = new NotificationDataDTO { ID = notificationDTO.ID, Notification_Heading = notificationDTO.Notification_Heading, Notification_Message = notificationDTO.Notification_Message, NotificationDueDate = notificationDTO.NotificationDueDate, NotificationActionLink = notificationDTO.NotificationActionLink, NotificationSource = notificationDTO.NotificationSource, PostcodeDistrict = notificationDTO.PostcodeDistrict, PostcodeSector = notificationDTO.PostcodeSector, NotificationTypeGUID = notificationDTO.NotificationType_GUID, NotificationPriorityGUID = notificationDTO.NotificationPriority_GUID }; return await notificationDataService.AddNewNotification(notificationDataDTO); } finally { loggingHelper.Log(methodName + LoggerTraceConstants.COLON + LoggerTraceConstants.MethodExecutionCompleted, TraceEventType.Verbose, null, LoggerTraceConstants.Category, LoggerTraceConstants.NotificationAPIPriority, LoggerTraceConstants.NotificationBusinessServiceMethodExitEventId, LoggerTraceConstants.Title); } } }
/// <summary> /// Get the notification details based on the UDPRN /// </summary> /// <param name="uDPRN">UDPRN id</param> /// <returns>NotificationDTO object</returns> public async Task <NotificationDataDTO> GetNotificationByUDPRN(int uDPRN) { using (loggingHelper.RMTraceManager.StartTrace("DataService.GetNotificationByUDPRN")) { string methodName = MethodHelper.GetActualAsyncMethodName(); loggingHelper.Log(methodName + LoggerTraceConstants.COLON + LoggerTraceConstants.MethodExecutionStarted, TraceEventType.Verbose, null, LoggerTraceConstants.Category, LoggerTraceConstants.NotificationAPIPriority, LoggerTraceConstants.NotificationDataServiceMethodEntryEventId, LoggerTraceConstants.Title); string actionLink = string.Format(USRNOTIFICATIONLINK, uDPRN); NotificationManager.Notification notification = await DataContext.Notifications .Where(notific => notific.NotificationActionLink == actionLink).SingleOrDefaultAsync(); NotificationDataDTO notificationDataDTO = new NotificationDataDTO(); Mapper.Initialize(cfg => cfg.CreateMap <NotificationManager.Notification, NotificationDataDTO>()); notificationDataDTO = Mapper.Map(notification, notificationDataDTO); loggingHelper.Log(methodName + LoggerTraceConstants.COLON + LoggerTraceConstants.MethodExecutionCompleted, TraceEventType.Verbose, null, LoggerTraceConstants.Category, LoggerTraceConstants.NotificationAPIPriority, LoggerTraceConstants.NotificationDataServiceMethodExitEventId, LoggerTraceConstants.Title); return(notificationDataDTO); } }
/// <summary> /// Add new notification to the database /// </summary> /// <param name="notificationDTO">NotificationDTO object</param> /// <returns>Task<int></returns> public async Task <int> AddNewNotification(NotificationDataDTO notificationDTO) { using (loggingHelper.RMTraceManager.StartTrace("DataService.AddNewNotification")) { int saveChangesAsync = default(int); string methodName = MethodHelper.GetActualAsyncMethodName(); loggingHelper.Log(methodName + LoggerTraceConstants.COLON + LoggerTraceConstants.MethodExecutionStarted, TraceEventType.Verbose, null, LoggerTraceConstants.Category, LoggerTraceConstants.NotificationAPIPriority, LoggerTraceConstants.NotificationDataServiceMethodEntryEventId, LoggerTraceConstants.Title); try { NotificationManager.Notification newNotification = new NotificationManager.Notification(); Mapper.Initialize(cfg => cfg.CreateMap <NotificationDataDTO, NotificationManager.Notification>()); newNotification = Mapper.Map <NotificationDataDTO, NotificationManager.Notification>(notificationDTO); DataContext.Notifications.Add(newNotification); loggingHelper.Log(methodName + LoggerTraceConstants.COLON + LoggerTraceConstants.MethodExecutionCompleted, TraceEventType.Verbose, null, LoggerTraceConstants.Category, LoggerTraceConstants.NotificationAPIPriority, LoggerTraceConstants.NotificationDataServiceMethodExitEventId, LoggerTraceConstants.Title); saveChangesAsync = await DataContext.SaveChangesAsync(); } catch (DbUpdateException dbUpdateException) { loggingHelper.Log(dbUpdateException, TraceEventType.Error); throw new DataAccessException(dbUpdateException, string.Format(ErrorConstants.Err_SqlAddException, string.Concat("notification for:", notificationDTO.NotificationActionLink))); } catch (NotSupportedException notSupportedException) { loggingHelper.Log(notSupportedException, TraceEventType.Error); notSupportedException.Data.Add(ErrorConstants.UserFriendlyErrorMessage, ErrorConstants.Err_Default); throw new InfrastructureException(notSupportedException, ErrorConstants.Err_NotSupportedException); } catch (ObjectDisposedException disposedException) { loggingHelper.Log(disposedException, TraceEventType.Error); disposedException.Data.Add(ErrorConstants.UserFriendlyErrorMessage, ErrorConstants.Err_Default); throw new ServiceException(disposedException, ErrorConstants.Err_ObjectDisposedException); } return(saveChangesAsync); } }