public static string GetTaskAssociation(RestCommand command, int reminderID)
        {
            TaskAssociation taskAssociation = TaskAssociations.GetTaskAssociation(command.LoginUser, reminderID);

            if (taskAssociation.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(taskAssociation.GetXml("TaskAssociation", true));
        }
Ejemplo n.º 2
0
        public bool AddAssociation(int taskID, int refID, int refType)
        {
            LoginUser loginUser = TSAuthentication.GetLoginUser();

            try
            {
                TaskAssociation taskAssociation = (new TaskAssociations(loginUser).AddNewTaskAssociation());
                taskAssociation.TaskID      = taskID;
                taskAssociation.RefID       = refID;
                taskAssociation.RefType     = refType;
                taskAssociation.DateCreated = DateTime.UtcNow;
                taskAssociation.CreatorID   = loginUser.UserID;
                taskAssociation.Collection.Save();
                string description = String.Format("{0} added task association to {1}.", TSAuthentication.GetUser(loginUser).FirstLastName, Enum.GetName(typeof(ReferenceType), refType));
                TaskLogs.AddTaskLog(loginUser, taskID, description);

                Task task = Tasks.GetTask(loginUser, taskID);
                if (task.UserID != null && loginUser.UserID != task.UserID)
                {
                    SendModifiedNotification(loginUser.UserID, task.TaskID);
                }

                if (refType == (int)ReferenceType.Contacts)
                {
                    TeamSupport.Data.User user = Users.GetUser(loginUser, refID);
                    taskAssociation             = (new TaskAssociations(loginUser).AddNewTaskAssociation());
                    taskAssociation.TaskID      = taskID;
                    taskAssociation.RefID       = user.OrganizationID;
                    taskAssociation.RefType     = (int)ReferenceType.Organizations;
                    taskAssociation.DateCreated = DateTime.UtcNow;
                    taskAssociation.CreatorID   = loginUser.UserID;
                    try
                    {
                        taskAssociation.Collection.Save();
                    }
                    catch (Exception e)
                    {
                        //TaskAssociation do not allow duplicates. This could happen when the company is already associated with the task.
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }