public async Task <int> SendNotification(NotificationUsers notification)
        {
            var response = await httpClient.PostAsJsonAsync("notifications", notification);

            response.EnsureSuccessStatusCode();
            var notificationId = await response.Content.ReadFromJsonAsync <int>();

            return(notificationId);
        }
        private static async Task TrackAndSendNotificationsAsync(NotificationUsers notification, SubscriptionUsers subscription)
        {
            // In a realistic case, some other backend process would track
            // order delivery progress and send us notifications when it
            // changes. Since we don't have any such process here, fake it.
            await Task.Delay(NotificationWithStatus.PreparationDuration);

            await SendNotificationAsync(notification, subscription, "Your notification has been dispatched!");

            await Task.Delay(NotificationWithStatus.DeliveryDuration);

            await SendNotificationAsync(notification, subscription, "Your notification is now delivered. Enjoy!");
        }
コード例 #3
0
        public void EditStatus(int id, int status, string reason)
        {
            SubTask subTask = unitOfWork.SubTasks.GetSubTaskWithTeam(id);

            subTask.Status = (Status)status;
            subTask        = unitOfWork.SubTasks.Edit(subTask);

            #region notification
            //--------Add Notification to DataBase

            string messege = $"*{subTask.Name}=*'s status has been updated to *{subTask.Status.ToString()}=* " +
                             $"at *{DateTime.Now}=* ";
            Notification Notification = new Notification
            {
                messege = messege,
                seen    = false
            };
            Notification      Savednotification = unitOfWork.Notification.Add(Notification);
            NotificationUsers notificationUsers = new NotificationUsers
            {
                NotificationId = Savednotification.Id,
                userID         = subTask.Task.Team.FK_TeamLeaderId
            };
            unitOfWork.NotificationUsers.Add(notificationUsers);

            //---------Send Notification to Employee
            hubContext.Clients.User(subTask.Task.Team.FK_TeamLeaderId).SendAsync("newNotification", messege, false, Savednotification.Id);
            #endregion


            Comment comment = new Comment
            {
                FK_sender   = userManager.GetUserId(HttpContext.User),
                FK_TaskID   = subTask.FK_TaskId,
                commentTime = DateTime.Now
            };
            comment.comment  = $"{subTask.Name} status has changed to {subTask.Status.ToString()}";
            comment.comment += reason;
            comment          = unitOfWork.Comments.Add(comment);

            //hubContext.Clients.User(subTask.Task.Team.FK_TeamLeaderId).SendAsync("newNotification",
            // $"");
        }
        public async Task <ActionResult <int> > SendNotification(NotificationUsers notification)
        {
            notification.CreatedTime = DateTime.Now;
            notification.Source      = "Action CRM";
            notification.Destination = "Client CRM";
            notification.UserId      = GetUserId();

            _context.NotificationUsers.Attach(notification);
            await _context.SaveChangesAsync();

            // In the background, send push notifications if possible
            var subscription = await _context.SubscriptionUsers.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync();

            if (subscription != null)
            {
                _ = TrackAndSendNotificationsAsync(notification, subscription);
            }

            return(notification.NotificationId);
        }
コード例 #5
0
        public void SendNotification(string messege, params string[] usersId)
        {
            Notification Notification = new Notification
            {
                messege = messege,
                seen    = false
            };
            Notification Savednotification = unitOfWork.Notification.Add(Notification);

            for (int i = 0; i < usersId.Length; i++)
            {
                NotificationUsers notificationUsers = new NotificationUsers
                {
                    NotificationId = Savednotification.Id,
                    userID         = usersId[i]
                };
                unitOfWork.NotificationUsers.Add(notificationUsers);

                //---------Send Notification to Employee
                hubContext.Clients.User(usersId[i]).SendAsync("newNotification", messege, false, Savednotification.Id);
            }
        }
        private static async Task SendNotificationAsync(NotificationUsers notification, SubscriptionUsers subscription, string message)
        {
            // For a real application, generate your own
            var publicKey  = "BNJd4yM_aOPtUZqI7IG8XWJNIHcg3iHHdmrWgv-6jLxMXySWeX7fRsl-xZcwj59GjYDWAwf4oc8UevQuViWgyPg";
            var privateKey = "W4Y49mec2mx6KoJ2I1yHgl0GoButX25SX1Sr2-GDl1I";

            var pushSubscription = new PushSubscription(subscription.Url, subscription.P256dh, subscription.Auth);
            var vapidDetails     = new VapidDetails("mailto:<*****@*****.**>", publicKey, privateKey);
            var webPushClient    = new WebPushClient();

            try
            {
                var payload = JsonSerializer.Serialize(new
                {
                    message,
                    url = $"mynotifications/{notification.NotificationId}",
                });
                await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error sending push notification: " + ex.Message);
            }
        }
コード例 #7
0
        public JsonResult AssignTasks(int taskId, int teamId)
        {
            if (ModelState.IsValid)
            {
                var task = unitOfWork.Tasks.GetById(taskId);
                task.FK_TeamId = teamId;
                var team = unitOfWork.Teams.GetById(teamId);
                unitOfWork.Complete();

                //--------Add Notification to DataBase

                string messege = $"*{HttpContext.User.Identity.Name}=* -Department Manager- has assigned new task" +
                                 $" *{task.Name}=* to your Team at *{DateTime.Now}=*";

                Notification Notification = new Notification
                {
                    messege = messege,
                    seen    = false
                };
                Notification      Savednotification = unitOfWork.Notification.Add(Notification);
                NotificationUsers notificationUsers = new NotificationUsers
                {
                    NotificationId = Savednotification.Id,
                    userID         = team.FK_TeamLeaderId
                };
                unitOfWork.NotificationUsers.Add(notificationUsers);

                //---------Send Notification to Team
                hubContext.Clients.User(notificationUsers.userID).SendAsync("newNotification", messege, false, Savednotification.Id);


                return(Json(new { teamName = team.Name }));
            }

            return(Json(new {  }));
        }
コード例 #8
0
        public IActionResult AddActivities(int id, List <Act> Acts, List <int> reDbId, List <DeletedDependecy> reDep)
        {
            // to convert from js date object to c# date object
            DateTime _jan1st1970 = new DateTime(1970, 1, 1, 23, 59, 59, DateTimeKind.Local);

            // (1)deleting the deleted dependencies (before editing the tasks)
            foreach (var deleted in reDep)
            {
                Activity     actToFollow  = unitOfWork.Tasks.GetById(deleted.followed);
                Activity     followingAct = unitOfWork.Tasks.GetById(deleted.following);
                Dependencies oldDep       = null;
                if (actToFollow != null && followingAct != null)
                {
                    oldDep = unitOfWork.Dependency.GetById(actToFollow.Id, followingAct.Id);
                }
                if (oldDep != null)
                {
                    unitOfWork.Dependency.Delete(oldDep.ActivityToFollowId, oldDep.FollowingActivityId);
                }
            }

            // (2)edit the old tasks
            foreach (Act act in Acts)
            {
                DateTime start = _jan1st1970.AddMilliseconds(act.start);
                DateTime end   = _jan1st1970.AddMilliseconds(act.end);
                // Edit the exisiting tasks
                if (act.dbId != 0 && !reDbId.Exists(d => d == act.dbId))
                {
                    Activity oldAct    = unitOfWork.Tasks.GetById(act.dbId);
                    int?     oldassign = oldAct.FK_DepID;
                    oldAct.Id           = act.dbId;
                    oldAct.FK_ProjectId = id;
                    oldAct.ViewOrder    = act.id;
                    oldAct.Name         = act.name;
                    oldAct.StartDate    = start;
                    oldAct.EndDate      = end;
                    oldAct.EstDuration  = act.duration;
                    oldAct.FK_DepID     = act.assignee;
                    oldAct.Progress     = 0;
                    //oldAct.Status = Status.Active;
                    oldAct.Priority = Priority.Medium;
                    if (act.assignee == 0)
                    {
                        oldAct.FK_DepID = null;
                    }
                    else if (oldassign != act.assignee) // notify about the assignment
                    {
                        #region notifications
                        string DepmanagerId = unitOfWork.Departments.GetById(act.assignee).FK_ManagerID;
                        string messege      = $"{HttpContext.User.Identity.Name}* -Project Manager- has assigned a new task -*{act.name}*- to your department at *{DateTime.Now.Date}";

                        //--------Add Notification to DataBase
                        Notification Notification = new Notification
                        {
                            messege = messege,
                            seen    = false
                        };
                        Notification      Savednotification = unitOfWork.Notification.Add(Notification);
                        NotificationUsers notificationUsers = new NotificationUsers
                        {
                            NotificationId = Savednotification.Id,
                            userID         = DepmanagerId
                        };
                        unitOfWork.NotificationUsers.Add(notificationUsers);

                        //---------Send Notification to Team
                        hubContext.Clients.User(DepmanagerId).SendAsync("newNotification", messege, false, Savednotification.Id);
                        #endregion
                    }
                    unitOfWork.Tasks.Edit(oldAct);
                }
                //else if (act.dbId != 0 && reDbId.Exists(d => d == act.dbId))
                //{
                //    Activity oldAct = unitOfWork.Tasks.GetById(act.dbId);
                //    oldAct.ViewOrder = -1; // to avoid conflict when getting the dependent task
                //}
            }

            // (3)Cancelling/Deleting the deleted activities
            foreach (var actId in reDbId)
            {
                //Activity activity = unitOfWork.Tasks.GetById(actId);
                //activity.Status = Status.Cancelled;
                //activity.ViewOrder = -1;  //to resolve the conflict in getting the tasks back
                //unitOfWork.Tasks.Edit(activity);

                unitOfWork.Tasks.Delete(actId);
            }

            // (4)adding the new tasks
            foreach (Act act in Acts)
            {
                DateTime start = _jan1st1970.AddMilliseconds(act.start);
                DateTime end   = _jan1st1970.AddMilliseconds(act.end);
                // adding all the new activities
                if (act.dbId == 0)
                {
                    Activity activity = new Activity
                    {
                        FK_ProjectId = id,
                        ViewOrder    = act.id,
                        Name         = act.name,
                        StartDate    = start,
                        EndDate      = end,
                        EstDuration  = act.duration,
                        FK_DepID     = act.assignee,
                        Progress     = 0,
                        Status       = Status.OnHold,
                        Priority     = Priority.Medium
                    };
                    if (act.assignee == 0)
                    {
                        activity.FK_DepID = null;
                    }
                    else // notify about the assignment
                    {
                        #region  notifications
                        string DepmanagerId = unitOfWork.Departments.GetById(act.assignee).FK_ManagerID;
                        string messege      = $"{HttpContext.User.Identity.Name} -Project Manager- has assigned a new task -{act.name}- to your department at {DateTime.Now.Date}";

                        //--------Add Notification to DataBase
                        Notification Notification = new Notification
                        {
                            messege = messege,
                            seen    = false
                        };
                        Notification      Savednotification = unitOfWork.Notification.Add(Notification);
                        NotificationUsers notificationUsers = new NotificationUsers
                        {
                            NotificationId = Savednotification.Id,
                            userID         = DepmanagerId
                        };
                        unitOfWork.NotificationUsers.Add(notificationUsers);

                        //---------Send Notification to Team
                        hubContext.Clients.User(DepmanagerId).SendAsync("newNotification", messege, false, Savednotification.Id);
                        #endregion
                    }
                    unitOfWork.Tasks.Add(activity);
                }
            }

            // (5)managing the related dependencies
            foreach (Act act in Acts)
            {
                #region oldWay
                // adding all the new dependencies related to the new activities (from the independent view)
                //if (act.Dependecies != null && act.dbId == 0)
                //{
                //    foreach (var dep in act.Dependecies)
                //    {
                //        Activity actToFollow = unitOfWork.Tasks.GetByProIdAndViewOrder(id, act.id);
                //        Activity followingAct = unitOfWork.Tasks.GetByProIdAndViewOrder(id, dep.id);
                //        Dependencies dependency = new Dependencies
                //        {
                //            ActivityToFollowId = actToFollow.Id,
                //            FollowingActivityId = followingAct.Id,
                //            Lag = dep.lag
                //        };
                //        unitOfWork.Dependency.Add(dependency);

                //    }
                //}
                #endregion
                // add the dependencies related to activities (from the dependent view)
                if (act.Dependecy != null && (act.dbId == 0 || !reDep.Exists(d => d.following == act.dbId)))
                {
                    List <Activity> actsToFollow  = unitOfWork.Tasks.GetByProIdAndViewOrder(id, act.Dependecy.id).ToList();
                    Activity        actToFollow   = GetFollowedActivity(actsToFollow, reDep);
                    List <Activity> followingActs = unitOfWork.Tasks.GetByProIdAndViewOrder(id, act.id).ToList();
                    Activity        followingAct  = GetFollowingActivity(followingActs, reDep);

                    Dependencies dependency = new Dependencies
                    {
                        ActivityToFollowId  = actToFollow.Id,
                        FollowingActivityId = followingAct.Id,
                        Lag = act.Dependecy.lag
                    };
                    Dependencies OldDependency = unitOfWork.Dependency.GetById(dependency.ActivityToFollowId, dependency.FollowingActivityId);
                    if (OldDependency == null)
                    {
                        unitOfWork.Dependency.Add(dependency);
                    }
                }
            }

            return(RedirectToAction(nameof(SetProjectDates), new { id = id }));
        }
コード例 #9
0
 public void ReplaceNotification(NotificationUsers notification)
 {
     Notification = notification;
 }
コード例 #10
0
 public void ResetNotification()
 {
     Notification = new NotificationUsers();
 }