public ActionResult GetByUserId(string ID) { var userInDB = _userManager.FindByIdAsync(ID).Result; if (userInDB == null) { return(BadRequest("ID not found!")); } var notification = _userNotificationService.GetByUserID(ID); if (notification == null) { return(Ok("There are not any notfication yet")); } var data = new List <NotificationViewModel>(); var listUserInRequest = _requestService.GetByUserID(ID); foreach (var item in notification) { var notificationInDb = _notificationService.GetByID(item.NotificationID); if (notificationInDb.NotificationType == NotificationType.UpdatedWorkflow) { var result = new NotificationViewModel { Fullname = _userManager.FindByIdAsync(ID).Result.FullName, EventID = notificationInDb.EventID, Message = "have update workflow", NotificationType = notificationInDb.NotificationType }; data.Add(result); } else if (notificationInDb.NotificationType == NotificationType.AcceptedRequest) { foreach (var userInRequest in listUserInRequest) { var result = new NotificationViewModel { Fullname = _userManager.FindByIdAsync(ID).Result.FullName, EventID = notificationInDb.EventID, Message = "Your request are accepted", NotificationType = notificationInDb.NotificationType, ApproverName = _userManager.FindByIdAsync(userInRequest.UserID).Result.FullName }; data.Add(result); } } else if (notificationInDb.NotificationType == NotificationType.ReceivedRequest) { foreach (var userInRequest in listUserInRequest) { var result = new NotificationViewModel { Fullname = _userManager.FindByIdAsync(ID).Result.FullName, EventID = notificationInDb.EventID, Message = "You received request", NotificationType = notificationInDb.NotificationType, ApproverName = _userManager.FindByIdAsync(userInRequest.UserID).Result.FullName }; data.Add(result); } } else if (notificationInDb.NotificationType == NotificationType.DeniedRequest) { foreach (var userInRequest in listUserInRequest) { var result = new NotificationViewModel { Fullname = _userManager.FindByIdAsync(ID).Result.FullName, EventID = notificationInDb.EventID, Message = "Your request are denied", NotificationType = notificationInDb.NotificationType, ApproverName = _userManager.FindByIdAsync(userInRequest.UserID).Result.FullName }; data.Add(result); } } else { return(NotFound()); } } var notficications = _userNotificationService.GetByUserID(ID); foreach (var item in notficications) { item.IsRead = true; } _notificationService.Save(); return(Ok(data)); }