/// <summary> /// Get web notification by id /// </summary> /// <param name="webNotificationId"></param> /// <returns></returns> public WebNotificationDomain GetById(int webNotificationId) { WebNotification webNotification = _context.WebNotification.FirstOrDefault(x => x.WebNotificationId == webNotificationId); NotificationDomain notificationDomain = _context.Notification.FirstOrDefault(x => x.NotificationId == webNotification.NotificationId).ToDomainModel(); return(webNotification.ToDomainModel(notificationDomain)); }
/// <summary> /// Update notification /// </summary> /// <param name="notification"></param> public void UpdateNotification(NotificationDomain notification) { ValidateNotificationModel(notification); ValidationHelper.GreaterThanZero(notification.Id, NotificationMessages.NotificationIdInvalid); ValidationHelper.NotNull(_notificationRepository.GetById(notification.Id), NotificationMessages.NotificationWithIdDoesNotExist); _notificationRepository.Update(notification); }
/// <summary> /// Add a notification /// </summary> /// <param name="notification"></param> /// <returns></returns> public int Add(NotificationDomain notification) { var notificationDb = new Notification().AddFromDomainModel(notification); _context.Notification.Add(notificationDb); _context.SaveChanges(); return(notificationDb.NotificationId); }
public static Notification UpdateFromDomainModel(this Notification obj, NotificationDomain domain) { obj.DateModified = DateTime.Now; obj.Title = domain.Title; obj.Content = domain.Content; obj.ExternalId = domain.ExternalId; obj.NotificationTypeId = domain.NotificationTypeId; obj.NotificationStatusId = domain.NotificationStatusId; return(obj); }
/// <summary> /// Update a notification /// </summary> /// <param name="notification"></param> public void Update(NotificationDomain notification) { var notificationDb = _context.Notification.First(x => x.NotificationId == notification.Id); if (notificationDb != null) { notificationDb.UpdateFromDomainModel(notification); _context.SaveChanges(); } }
private void ValidateNotificationModel(NotificationDomain notification) { ValidationHelper.NotNull(notification, NotificationMessages.NotificationNotProvided); ValidationHelper.NotNull(notification.ExternalId, NotificationMessages.NotificationExternalIdNotProvided); ValidationHelper.NotNull(notification.NotificationStatusId, NotificationMessages.NotificationStatusIdNotProvided); ValidationHelper.NotNull(notification.NotificationTypeId, NotificationMessages.NotificationTypeIdNotProvided); ValidationHelper.GreaterThanZero(notification.NotificationStatusId, NotificationMessages.EmailNotificationStatusIdInvalid); ValidationHelper.GreaterThanZero(notification.NotificationTypeId, NotificationMessages.NotificationTypeIdInvalid); ValidationHelper.NotNull(_notificationStatusRepository.GetById(notification.NotificationStatusId), NotificationMessages.NotificationStatusIdDoesNotExist); ValidationHelper.NotNull(_notificationTypeRepository.GetById(notification.NotificationTypeId), NotificationMessages.NotificationTypeWithIdDoesNotExist); }
public void AddNotification_Fail_NotificationTypeIdNull() { var Notification = new NotificationDomain() { Id = 1, Content = "Test content", NotificationStatusId = 2, ExternalId = new Guid(), Title = "TEST", }; _notificationManipulation.AddNotification(Notification); }
public NotificationDomain ReadById(int id) { NotificationDomain list = new NotificationDomain(); DataProvider.ExecuteCmd("dbo.Notifications_SelectByUserBaseId", inputParamMapper: (SqlParameterCollection inputs) => { inputs.AddWithValue("@Id", id); }, singleRecordMapper: (IDataReader reader, short resultSet) => { list = DataMapper <NotificationDomain> .Instance.MapToObject(reader); }); return(list); }
public static Notification AddFromDomainModel(this Notification obj, NotificationDomain domain) { if (obj == null) { obj = new Notification(); } obj.NotificationId = domain.Id; obj.Title = domain.Title; obj.Content = domain.Content; obj.ExternalId = domain.ExternalId; obj.DateCreated = DateTime.Now; obj.DateModified = null; obj.NotificationTypeId = domain.NotificationTypeId; obj.NotificationStatusId = domain.NotificationStatusId; return(obj); }
private void sendNotification(String content, int tenantId) { Guid externalId = _tenantRepository.GetById(tenantId).Identifier; NotificationDomain notification = new NotificationDomain(); notification.Content = content; notification.DateCreated = DateTime.UtcNow; notification.DateModified = DateTime.UtcNow; notification.ExternalId = externalId; notification.Title = "Incident resolved"; notification.NotificationStatusId = 3; //type = Device Ping notification.NotificationTypeId = 6; _notificationRepository.Add(notification); }
public List <NotificationDomain> Notifications_GetByTimeAndUserId(DateTime time, string userId) { List <NotificationDomain> notificationList = null; NotificationDomain notification = null; try { DataProvider.ExecuteCmd(GetConnection, "dbo.Notifications_GetByTimeAndUserId" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@time", time); paramCollection.AddWithValue("@userId", userId); }, map : delegate(IDataReader reader, short set) { int startingIndex = 0; notification = new NotificationDomain(); notification.NotificationId = reader.GetSafeInt32(startingIndex++); notification.UserId = reader.GetSafeString(startingIndex++); notification.DateCreated = reader.GetSafeDateTime(startingIndex++); notification.DateUpdated = reader.GetSafeDateTime(startingIndex++); notification.Category = reader.GetSafeString(startingIndex++); notification.Message1 = reader.GetSafeString(startingIndex++); notification.Is_Read = reader.GetSafeBool(startingIndex++); notification.Link = reader.GetSafeString(startingIndex++); notification.Message2 = reader.GetSafeString(startingIndex++); notification.Message3 = reader.GetSafeString(startingIndex++); if (notificationList == null) { notificationList = new List <NotificationDomain>(); } notificationList.Add(notification); }); } catch (Exception ex) { Console.WriteLine(ex.ToString()); notificationList = null; } return(notificationList); }
public static WebNotificationDomain ToDomainModel(this WebNotification obj, NotificationDomain domain) { return(obj == null ? null : new WebNotificationDomain() { Id = obj.WebNotificationId, Seen = obj.Seen, DateSeen = obj.DateSeen, NotificationId = obj.NotificationId, UserInfoId = obj.UserInfoId, UserTenantId = obj.UserTenantId, Title = domain.Title, Content = domain.Content, ExternalId = domain.ExternalId, DateCreated = domain.DateCreated, DateModified = domain.DateModified, NotificationStatusId = domain.NotificationStatusId, NotificationTypeId = domain.NotificationTypeId }); }
public IHttpActionResult Add(AddNotificationRequest request) { request.ValidateNotNull(); // convert from request model to domain model var notificationDomain = new NotificationDomain() { Title = request.Title, Content = request.Content, ExternalId = request.ExternalId, NotificationStatusId = request.NotificationStatusId, NotificationTypeId = request.NotificationTypeId, }; return(Ok(new AddNotificationResponse() { Data = _notificationManipulation.AddNotification(notificationDomain), Success = Common.Enumerations.ResponseStatus.Succeeded })); }
public IHttpActionResult GetAllNotificationsByUserId(int userId) { if (userId < 1) { return(BadRequest(NotificationMessages.UserIdInvalid)); } var data = _notificationUserManipulation.GetNotificationUserByUserId(userId); if (data == null) { return(NotFound()); } ICollection <int> listOfNotificationIds = new List <int>(); foreach (NotificationUserDomain notificationUser in data) { listOfNotificationIds.Add(notificationUser.NotificationId); } ICollection <NotificationDomain> listOfNotifications = new List <NotificationDomain>(); foreach (int notificationId in listOfNotificationIds) { NotificationDomain tempNotification = _notificationManipulation.GetNotificationById(notificationId); if (!listOfNotifications.Any(x => x.Id == tempNotification.Id)) { listOfNotifications.Add(tempNotification); } } return(Ok(new GetAllNotificationsResponse() { Data = listOfNotifications, Success = Common.Enumerations.ResponseStatus.Succeeded })); }
/// <summary> /// Add a notification /// </summary> /// <param name="notification"></param> /// <returns></returns> public int AddNotification(NotificationDomain notification) { ValidateNotificationModel(notification); return(_notificationRepository.Add(notification)); }
public async void AddNotification(NotificationDomain notification) { await _mediator.Publish(new NotificationDomain(notification.MessageId, notification.Message)); }