public void InsertOrUpdate(Notification notification)
 {
     if (notification.NotificationID == default(long)) {
         // New entity
         context.Notifications.Add(notification);
     } else {
         // Existing entity
         context.Entry(notification).State = System.Data.Entity.EntityState.Modified;
     }
 }
Beispiel #2
0
        private void SaveNotification(Task task, bool isTaskInsert,bool isSubTask,bool isTaskStatusChanged)
        {
            string phrase = "";
            if (task.Users != null)
            {
                foreach (User user in task.Users)
                {
                    Notification notification = new Notification();
                    if (isTaskInsert)
                    {
                        if (!isSubTask)
                        {
                            phrase = " Has assigned you on the Task --";
                        }
                        else
                        {
                            phrase = " Has assigned you on the Subtask --";
                        }

                        User createdUser = unitOfWork.UserRepository.GetUserByUserID(task.CreatedBy);
                        notification.Title = createdUser.FirstName + " " + createdUser.LastName + phrase + task.Title;
                    }
                    else
                    {
                        if (!isTaskStatusChanged)
                        {
                            if (!isSubTask)
                            {
                                phrase = " Has modify the Task --";
                            }
                            else
                            {
                                phrase = " Has modify the Subtask --";
                            }
                        }
                        else
                        {
                            if (!isSubTask)
                            {
                                phrase = string.Format(" Has changed the task status to {0} --",task.Status.ToString());
                            }
                            else
                            {
                                phrase = string.Format(" Has changed the subtask status to {0} --",task.Status.ToString());
                            }
                        }
                        User modifiedUser = unitOfWork.UserRepository.GetUserByUserID(task.ModifieddBy);
                        notification.Title = modifiedUser.FirstName + " " + modifiedUser.LastName + phrase + task.Title;
                    }
                    notification.UserID = user.UserId;
                    notification.Description = notification.Title;
                    notification.ProjectID = task.ProjectID;
                    notification.TaskID = task.TaskID;
                    unitOfWork.NotificationRepository.InsertOrUpdate(notification);
                    unitOfWork.Save();
                }
            }
            if (task.Followers != null)
            {
                foreach (User user in task.Followers)
                {
                    Notification notification = new Notification();
                    if (isTaskInsert)
                    {
                        if (!isSubTask)
                        {
                            phrase = " Has added you as a follower on the Task --";
                        }
                        else
                        {
                            phrase = " Has added you as a follower on the Subtask --";
                        }
                        User createdUser = unitOfWork.UserRepository.GetUserByUserID(task.CreatedBy);
                        notification.Title = createdUser.FirstName + " " + createdUser.LastName + phrase + task.Title;
                    }
                    else
                    {
                        if (!isSubTask)
                        {
                            phrase = " Has modify the Task --";
                        }
                        else
                        {
                            phrase = " Has modify the Subtask --";
                        }
                        User modifiedUser = unitOfWork.UserRepository.GetUserByUserID(task.ModifieddBy);
                        notification.Title = modifiedUser.FirstName + " " + modifiedUser.LastName + phrase + task.Title;
                    }
                    notification.UserID = user.UserId;
                    notification.Description = notification.Title;
                    notification.ProjectID = task.ProjectID;
                    notification.TaskID = task.TaskID;
                    unitOfWork.NotificationRepository.InsertOrUpdate(notification);
                    unitOfWork.Save();
                }
            }
        }
Beispiel #3
0
        private void SaveNotification(Project project,bool isProjectInsert)
        {
            if (project.Users != null)
            {
                foreach (User user in project.Users)
                {

                    Notification notification = new Notification();
                    if (isProjectInsert)
                    {
                        User createdUser = unitOfWork.UserRepository.GetUserByUserID(project.CreatedBy);
                        notification.Title = createdUser.FirstName + " " + createdUser.LastName + " Has added you on the porject --" + project.Name;
                    }
                    else
                    {
                        User modifiedUser = unitOfWork.UserRepository.GetUserByUserID(project.ModifieddBy);
                        notification.Title = modifiedUser.FirstName + " " + modifiedUser.LastName + " Has modify the porject --" + project.Name;
                    }
                    notification.UserID = user.UserId;
                    notification.Description = notification.Title;
                    notification.ProjectID = project.ProjectID;
                    unitOfWork.NotificationRepository.InsertOrUpdate(notification);
                    unitOfWork.Save();
                }
            }
        }